Help using Base SAS procedures

sas entries manipulation

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

sas entries manipulation

save i have the following data:

Observation
x
y
112
23
32

as you can see, column y is not complete. BUT, all rows in column y should take the same value:

Observation
x
y
112
232
322

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


Accepted Solutions
Solution
‎10-02-2011 02:59 PM
PROC Star
Posts: 7,416

sas entries manipulation

One way would be:

data want (drop=_Smiley Happy;

  set have (rename=(y=_y));

  retain y;

  if _n_ eq 1 then y=_y;

  if x gt y;

run;

View solution in original post


All Replies
Solution
‎10-02-2011 02:59 PM
PROC Star
Posts: 7,416

sas entries manipulation

One way would be:

data want (drop=_Smiley Happy;

  set have (rename=(y=_y));

  retain y;

  if _n_ eq 1 then y=_y;

  if x gt y;

run;

Contributor
Posts: 44

sas entries manipulation

thanks a lot! that solved the problem! Smiley Happy

just curious though....

what are these two doing?

drop=_:

rename=(y=_y)

thanks,

c

PROC Star
Posts: 7,416

sas entries manipulation

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:

http://www2.sas.com/ proceedings/sugi29/054-29.pdf

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 112 views
  • 0 likes
  • 2 in conversation