Reputation: 71
I have a data set x=(1,4,7,8,10,...................) which has these random values. I want to find the median of the data set and then store it in a call symput so that i can use to find the difference of each of the observation from the median.
what is the function to find the median of this data set by just mentioning the variable name?
I want the data in the below format:
X X-median
1 1-median
4 4-median
7 7-median
8 8-median
10 10-median
Upvotes: 0
Views: 572
Reputation: 1945
This can be easily done in PROC SQL;
Let's say you have the x values in table A and create a new table B:
PROC SQL;
CREATE TABLE B AS SELECT x,median(x) AS median,x-median(x) AS offset FROM A;
QUIT;
Upvotes: 0
Reputation: 63424
Don't use it in a macro variable. Just combine it as a dataset.
proc means data=sashelp.class noprint;
var age;
output out=age_median median(age)=age_median;
run;
data class_fin;
if _n_=1 then set age_median(keep=age_median);
set sashelp.class;
age_minus_median = age - age_median;
run;
When you set a dataset this way (a one row dataset with if _n_=1
) you get its value(s) copied onto every row on the dataset, sort of like if you merged it with some universal by value.
Upvotes: 1