BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have two data sets with the same variables. Let's say for 10 observations, I want to calculate the median percent change from date1 to date2. E.g.

Data set 1 values from June:
BP
120
130
90
.....

Data set 2 values from September:
BP
110
97
120
....

What is the median percent change/difference in these values from one date to the next? I know I can do it manually but I have a lot of observations and I want to know how to do this in SAS.

Thank you!
2 REPLIES 2
deleted_user
Not applicable
Try this out, if it can be of any help:

*** Merge both the dataset. If both the datasets have day variable, use it in BY for merging ***;

data combine;
merge data1 data2;
run;

*** calculat epercent change ***;

data pctchg;
set combine;
pctchg=(bp2-bp1)*100/bp1;
run;

*** Use means to get the median ***;

proc means data=pctchg median;
var pctchg;
output out=summ median=median;
run;
Doc_Duke
Rhodochrosite | Level 12
To me, the question is not well defined.

If you want the median of the date-specific changes, then Sandeep's solution works as long as both months have the same number of days.

If you want the median percent change of all the measures in June to all the measures in September, then you want the percent change on all possible combinations of June-September measures. This involves getting a Cartesian product of the measures in June and September and then getting the median of those combinations. For June-September, there would be 900 (30x30) combinations.

Substitute a PROC SQL for Sandeep's merge

*untested code;
PROC SQL;
CREATE TABLE combined AS
SELECT data1.BP AS BPJune,
data2.BP as BPSept
FROM data1
OUTER JOIN data2;
QUIT;
RUN;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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