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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1360 views
  • 1 like
  • 2 in conversation