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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

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