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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.