BookmarkSubscribeRSS Feed
CJK7
Calcite | Level 5

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.

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
CJK7
Calcite | Level 5

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!

mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Register Now

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!

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
  • 3 replies
  • 364 views
  • 1 like
  • 3 in conversation