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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 425 views
  • 0 likes
  • 2 in conversation