I have just started using SAS recently. I am attempting to create a new table newtable based on another table oldtable.
Let's say the oldtable contains variable OldPrice. I want to create newtable with a new variable NewPrice calculated based on OldPrice. Then filter the newtable to only show NewPrice which is larger than 10.
Below is the sample code I have.
data newtable;
set oldtable;
NewPrice = OldPrice * 2
where NewPrice > 10;
run;
However, I receive error message saying that NewPrice is not a variable of oldtable.
CodePudding user response:
WHERE operates on the data before it reaches the data step. To conditional delete an observation you need to use IF.
For exameple just use a subsetting IF instead of WHERE.
data newtable;
set oldtable;
NewPrice = OldPrice * 2;
if NewPrice > 10;
run;
Of explicitly delete the observations you don't want.
data newtable;
set oldtable;
NewPrice = OldPrice * 2;
if NewPrice <= 10 then delete;
run;
CodePudding user response:
A WHERE statement expression can only use variables in the program data vector (PDV) that come from a SET statement.
The data set option WHERE= can be used in the specification of an input or output data set.
Statement
data want; set have; where expression; ...
Option
data want; set have(where=(expression)); ...
or
data want(where=(expression)); set have; ...
