N/A
Posts: 0

Calculate Median percent change

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!
N/A
Posts: 0

Re: Calculate Median percent change

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;
Posts: 2,122

Re: Calculate Median percent change

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;
Discussion stats
• 2 replies
• 2770 views
• 0 likes
• 2 in conversation