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

data have;
infile datalines;
input ID $6. code $ date $;
datalines;
AP9734 300 6/19/2019
AP9734 301 2/15/2020
run;


WANT:

ID code1 code2 date1 date1
AP9734 300 301 6/19/2019 2/15/2020

1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11

not sure why you want to do it, if it's for reporting purpose, you should look into proc report. 

 

But anyways, here is a quick solution

data mrg;
  merge  have (obs=1 firstobs=1 rename=(code=code1 date=date1)) 
 		 have (obs=2 firstobs=2  rename=(code=code2 date=date2));
  by id;
run;

Capture.JPG

View solution in original post

2 REPLIES 2
ballardw
Super User

What if you have 3 or more values the same for id?

Is it always exactly 2?

ghosh
Barite | Level 11

not sure why you want to do it, if it's for reporting purpose, you should look into proc report. 

 

But anyways, here is a quick solution

data mrg;
  merge  have (obs=1 firstobs=1 rename=(code=code1 date=date1)) 
 		 have (obs=2 firstobs=2  rename=(code=code2 date=date2));
  by id;
run;

Capture.JPG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 869 views
  • 0 likes
  • 3 in conversation