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

I have data like below :

 

ID visit m1 m2 m3 m4
1 week1 10      
1 week1   13    
1 week1     15  
1 week1       14
2 week2 12      
2 week2   11    
2 week2     14  
2 week2       13
3 week3 13      
3 week3   10    
3 week3     11  
3 week3       12

 

And I want to have data like :

ID visit m1 m2 m3 m4
1 week1 10 13 15 14
2 week2 12 11 14 13
3 week3 13 10 11 12

 

One way is to output 4 data for m1, m2, m3 and m4 and then merge. 

I wonder if there is a simpler way to do it? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
1 REPLY 1
Reeza
Super User

Use SQL and take max of each column per id

 

use update trick

data want;

Update have (obs=0) have;

by id visit;

run;

 

https://communities.sas.com/t5/Base-SAS-Programming/How-can-I-combine-multiple-rows-to-a-single-row/...

sas-innovate-2024.png

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.

 

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
  • 1 reply
  • 818 views
  • 3 likes
  • 2 in conversation