BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ppchennn
Fluorite | Level 6

I was learning about the RETAIN statement and came across a paper about it (RETAIN or NOT? Is LAG Far Behind? by Venky Chakravarthy).

 

The example is about using the retain statement to replace missing value with substituted data (substitute with the last observation).

 

I was confused with a line in the example data step.

 

The example is like this:

DATA SYSTOLIC2;
INPUT PTNO SBP;
CARDS;
1 120
1 .
1 140
2 150
2 130
2 .
3 135
3 .
3 .
3 .
;
RUN;
Data impute2 ;
set systolic2 ;
by ptno ;
retain newsbp ;
if first.ptno then newsbp = . ; *I was confused by this line.;
if not missing(sbp) then newsbp = sbp ;
run ;

The data step creates a new variable called newsbp to replace the missing value in the sbp variable with the last observation.


I tried to delete the line that confuses me and the output and log was the same with the example.


Do we really need to set the first newsbp of a ptno missing to make the data step work?

 

Since all the sbp of first.ptno is not missing, what is the purpose of setting the first newsbp missing?

 

 

It would be great if anyone could help, thanks! 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

It is useless in this specific example but,as you say, if there was a ptno with first observation missing,
it would avoid to report the spb from the previous ptno.

View solution in original post

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

It is useless in this specific example but,as you say, if there was a ptno with first observation missing,
it would avoid to report the spb from the previous ptno.

ppchennn
Fluorite | Level 6

At first, I thought the by ptno line is enough for avoiding the problem of getting the observation from the previous ptno.
I tried to change the example sbp data and got the idea of what you mean.

 

Thanks a lot for the help!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 976 views
  • 1 like
  • 2 in conversation