BookmarkSubscribeRSS Feed
mariko5797
Pyrite | Level 9

See Attached. Essentially, I want to have the BMI and treatment group repeated for the given ID. Then I want to assess whether the time frame was during or after by comparing DATE_1 to DATE_2. If DATE_2 occurred before the last DATE_1 for "during", then I want the time period for the X measurements to be labeled "during". If DATE_2 occurred after the first DATE_1 for "after", then I want the time period for X measurements to be labeled "after". I have attempted using the retain statement, but it doesn't seem to do what I expected it to. It seemed to have no effect on the data.

 

proc sort data = working nodupkey;
 by ID PERIOD DATE_1;
 run; 

data working; 
set working; 
by ID; 
retain TRT BMI DATE_1; 
run; 
2 REPLIES 2
mariko5797
Pyrite | Level 9

I'm not sure why, but I didn't have the text tools to make the post easy to follow initially. Here's the code attempt rewritten:

 

proc sort data = working nodupkey; 
 by ID PERIOD DATE_1; 
run; 

data working; 
 set working; 
 by ID; 
 retain TRT BMI DATE_1; 
run;
 /* also tried to retain X1, X2, X3 instead */
Reeza
Super User
Not sure why your post didn't work but I edited it.

Retain doesn't really work on existing variables so if you want to use retain type functionality, create a new variable to hold the values. Looking at the Excel, RETAIN is not the correct solution here. UPDATE may be more appropriate.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2325 views
  • 0 likes
  • 2 in conversation