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

Have this..

PID Col1 Col2 p1 p2
3527 21      
3527     99  
3527        
3528        
3528     25.32  
3400     26  
3400        
3400        
3200     12  
3200 33      
3200       30.2
3201       27
3201        
3922   19    
3922        
3923 23      
3922        
3923       99
3922       35
3923        

Want this..

PID Col1 Col2 p1 p2
3527 21   99  
3528     25.32  
3400     26  
3200 33 12   30.2
3201       27
3923 23     99
3922   19   35
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

By far, the easiest way to achieve this is first to sort your data:

proc sort data=have;
   by pid;
run;

Then roll up the observations:

data want;
   update have (obs=0) have;
   by pid;
run;

If for some reason you don't want to sort your data, there are still ways to do it but they become more complex.

View solution in original post

6 REPLIES 6
Astounding
PROC Star

By far, the easiest way to achieve this is first to sort your data:

proc sort data=have;
   by pid;
run;

Then roll up the observations:

data want;
   update have (obs=0) have;
   by pid;
run;

If for some reason you don't want to sort your data, there are still ways to do it but they become more complex.

Stalk
Pyrite | Level 9
Looks like this solution worked but still have to test it. Can you explain what exactly this update is doing?
For other I have both numeric and char fields so proc Summary might not be option .
Thank you all for your assistance.
Astounding
PROC Star

UPDATE processes each PID separately.  It takes the observations for that PID one at a time, and uses any non-missing values it finds to replace what was there before.  So it ignores missing values.  When all the observations for a PID have been processed, it outputs the result ... one observation per PID.

ballardw
Super User

Rules may help.

Such what happens if you have two values for any of the Col1, Col2, P1 or P2 variables within a PID value?

And are those variables numeric or character?

Are you looking for a data set or a report (people read these)?

ballardw
Super User

@Kurt_Bremser wrote:

If col1 -- p2 are numeric, use PROC SUMMARY:

proc summary data=have;
class pid;
var col1 col2 p1 p2;
output out=want (drop=_:) max()=;
run;

Which is exactly why I was asking about any of the variables having multiple values and the needed results.

Might actual want a sum or mean or ???

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1245 views
  • 1 like
  • 4 in conversation