turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Health Care and Pharma
- /
- SAS in Health Care Related Fields
- /
- Calculate Median percent change

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-09-2007 03:45 PM

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!

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-10-2007 01:11 AM

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;

*** 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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-11-2007 02:32 PM

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;

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;