BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Huijing
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

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

Huijing
Calcite | Level 5

Thank you!

Pmyosh
Obsidian | Level 7

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 ;

        

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 406 views
  • 0 likes
  • 3 in conversation