I have a wide form dataset in which each patient has multiple MME measures (MME_1 - MME_153) and a corresponding date (Order_Date_1 - Order_Date_153). Each patient has a pre and post intervention period, based on the variable index_date. I need to create a variable that is the sum of all MME measures in the pre period and another variable that is the sum of all MME measures in the post period.
This is incredibly easy with a long data set and PROC SUMMARY. You can use PROC TRANSPOSE to create the long data set. If you provide a small example of the data with say 10 patients, 3 variables and the corresponding 3 dates and the pre and post intervention dates, I can provide code. Use these instructions to provide data as SAS Data step code. Do not attach files or show us screen captures.
I wasn't able to provide the example data, but your comment did put me on the right path. I was able to manipulate the data as needed in long form, then transpose back to wide form. Thanks!
You can use two arrays, each with 153 elements - one array for the dates, and one for the mme values. Then just iterate through the 153 elements of each array, test the date and add the mme to the pre- or post- summary value, as appropriate:
data want;
array odate order_date_1 - order_date_153;
array mme mme_1 - mme_153;
do over odate;
if odate>index_date then post_sum=sum(post_sum,mme);
else if odate>. then pre_sum=sum(pre_sum,mme);
end;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.