save i have the following data:
Observation | x | y |
---|---|---|
1 | 1 | 2 |
2 | 3 | |
3 | 2 |
as you can see, column y is not complete. BUT, all rows in column y should take the same value:
Observation | x | y |
---|---|---|
1 | 1 | 2 |
2 | 3 | 2 |
3 | 2 | 2 |
Two Questions:
First, I want to know how I can do that on SAS.
Next, I need want to keep observations such that x>=y. How can I do that?
Thanks,
C
One way would be:
data want (drop=_:);
set have (rename=(y=_y));
retain y;
if _n_ eq 1 then y=_y;
if x gt y;
run;
One way would be:
data want (drop=_:);
set have (rename=(y=_y));
retain y;
if _n_ eq 1 then y=_y;
if x gt y;
run;
thanks a lot! that solved the problem!
just curious though....
what are these two doing?
drop=_:
rename=(y=_y)
thanks,
c
Just a couple of shortcuts. The rename statement changes the name of variable y, when the file is set, so that it will be seen to be variable _y; I did it that way so that the later missing values of y wouldn't override the desired value from the first record.
The drop statement, then, just uses the semicolon as a wild card. It says, in essence, to drop any variable that starts with an underscore (i.e., variable _y).
The semi colon has lots of under used useage in SAS as stated, nicely, in:
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: