Hi, I have the following source data that need to be combined and wonder if anyone could provide some thoughts on how to do it. The source data is:
Policy Var1 Var2 Var3
1234 SP500
1234 NASDAQ
1234 Russell
I want to have it look like the following:
Policy Var1 Var2 Var3
1234 SP500 NASDAQ Russell
Any ideas are appreciated!
data have;
input Policy ( Var1 Var2 Var3 ) ($);
cards;
1234 SP500 . .
1234 . NASDAQ .
1234 . . Russell
;
data want;
update have(obs=0) have;
by policy;
run;
proc print noobs;run;
Policy Var1 Var2 Var3
1234 SP500 NASDAQ Russell
data have;
input Policy ( Var1 Var2 Var3 ) ($);
cards;
1234 SP500 . .
1234 . NASDAQ .
1234 . . Russell
;
data want;
update have(obs=0) have;
by policy;
run;
proc print noobs;run;
Policy Var1 Var2 Var3
1234 SP500 NASDAQ Russell
Thank you!
Hi, if you have 1 value per variable per policy then you can do this
PROC SQL ;
CREATE TABLE want AS
SELECT policy
,MAX(Var1) AS Var1
,MAX(Var2) AS Var2
,MAX(Var3) AS Var3
FROM have
GROUP BY policy ;
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.