Hi,
I'm working with a dataset that has the following format:
ID Var1 Var2 Var3 Var4
1 .5 . . .
1 . .5 . .
1 . . .5 .
1 . . . .5
2 .7 . . .
2 . .7 . .
2 . . .7 .
2 . . . .7
etc
And I want to combine the observations so the end result is:
ID Var1 Var2 Var3 Var4
1 .5 .5 .5 .5
2 .7 .7 .7 .7
Any suggestions?
Thank you!
here's another option but I like Hai.Kuo's better:
data have;
infile cards dsd;
input ID Var1 Var2 Var3 Var4;
cards;
1,.5,.,.,.
1,.,.5,.,.
1,.,.,.5,.
1,.,.,.,.5
2,.7,.,.,.
2,.,.7,.,.
2,.,.,.7,.
2,.,.,.,.7
;
proc sql;
create table want as
select distinct
id,
max(var1)as var1,
max(var2)as var2,
max(var3)as var3,
max(var4)as var4
from have
group by id
order by id;
Or
proc sql;
create table want as
select id,sum(var1) as var1,sum(var2) as var2, sum(var3) as var3, sum(var4) as var4 from have
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 save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.