Hello
I want to calculate for each customer median of variable X and then to re-merge it with the original data set.
Thank you so much
Data tbl1;
input ID ddate x;
cards;
1 1901 15
1 1902 18
1 1903 22
1 1904 16
1 1905 35
1 1906 18
1 1907 21
2 1901 10
2 1902 15
2 1903 13
2 1904 15
2 1905 30
2 1906 30
2 1907 28
3 1901 40
3 1902 40
3 1903 40
3 1904 40
3 1905 40
3 1906 40
3 1907 40
;
run;
Do like this
proc sql;
create table tbl2 as
select *, median(x) as median_x
from tbl1
group by ID;
quit;
Do like this
proc sql;
create table tbl2 as
select *, median(x) as median_x
from tbl1
group by ID;
quit;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.