BookmarkSubscribeRSS Feed
ari
Quartz | Level 8 ari
Quartz | Level 8

Have: 

IDDayR
1  
1  
1Day 1 
1Day 2run 0
1  
1  
1  
1  
1Day1run 1
1  
1Day2run2
1  
1  

 

Want:

IDDayR
1  
1  
1Day 1 
1Day 2run 0
1 run 0
1 run 0
1 run 0
1 run 0
1Day1run 1
1 run 1
1Day2run2
1 run2
1 run2

 

I want to retain the value of R based on the value of Day (R value carried forward until the next Day

). Any help to achieve this using the retain function?

 

Thanks,

4 REPLIES 4
data_null__
Jade | Level 19

This is pretty standard LOCF.

 

data run;
   infile cards missover;
   input ID Day &$ run &$;
   cards;
1 
1 
1 Day 1
1 Day 2  run 0
1 
1 
1 
1 
1 Day1  run 1
1 
1 Day2  run 2
1 
1 
;;;;
   run;
proc print;
   run;
data run;
   if 0 then set run;
   update run(keep=id obs=0) run(keep=id run);
   by id;
   set run(keep=day);
   output;
   run;
proc print;
   run; 

Capture.PNG

ari
Quartz | Level 8 ari
Quartz | Level 8

@data_null__. It works but difficult to understand to modify to copy the remaining variables as such in the dataset. My original dataset contains 50 variables and those be copied as such. Any pointers? Thanks

data_null__
Jade | Level 19

@ari wrote:

@data_null__. It works but difficult to understand to modify to copy the remaining variables as such in the dataset. My original dataset contains 50 variables and those be copied as such. Any pointers? Thanks


 

Did you do any reading in the SAS online documentation about the statements used in the program?

 

change

 

set run(keep=day);

to

set run(drop=id run);

All variables in RUN except ID and RUN are added but their values are not carried forward.

 

The SET statement is to bring in all the variables that you do not want have values carried forward.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 4 replies
  • 1242 views
  • 1 like
  • 2 in conversation