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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.