BookmarkSubscribeRSS Feed
devindaj
Calcite | Level 5

Hi, have the following data set which captures key process dates by an ID key....

 

ID_keyprocessprocess_date
1x01-01-15
1y02-01-15
2x

03-01-15

 

and want to convert it to the below, where the process value becomes the name of the process date... 

 

ID_keyx_process_datey_process_date
101-01-1502-01-15
203-01-15 

 

hope that made sense...

 

what would be the best way to do this ??

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

data have;
infile cards dsd;
informat id_key 1. process $1. process_date mmddyy10.;
format id_key 1. process $1. process_date mmddyy10.;
input ID_key    process$    process_date;
cards;
1,x,01-01-15
1,y,02-01-15
2,x,03-01-15
;run;

proc transpose data=have out=tran_have(drop=process _name_)prefix=Process_Date_;by id_key process;id process;

data want(keep=id_key X_Process_date Y_Process_Date);
set tran_have(rename=process_date_y=Y_Process_date);
by id_key;
retain X_Process_date;
if first.id_key then X_Process_date = Process_Date_X;
if last.id_key;
format X_Process_Date mmddyy10.;
run;

andreas_lds
Jade | Level 19

By using suffix option instead of prefix you can skip the last datastep.

Ksharp
Super User

Check MERGE skill, me , Matt and Arthur.T proposed :

http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf

 

data have;
infile cards dsd;
informat id_key 1. process $1. process_date mmddyy10.;
format id_key 1. process $1. process_date mmddyy10.;
input ID_key    process$    process_date;
cards;
1,x,01-01-15
1,y,02-01-15
2,x,03-01-15
;
run;
proc sql;
select distinct catt('have(where=(id_key=',id_key,' and process="',process,'") rename=(process_date=',process,'_process_date))') into : merge separated by ' '
 from have;
quit;
data want;
 merge &merge;
 by id_key ;
 drop process;
run;
Ksharp
Super User

 

data have;
infile cards dsd;
informat id_key 1. process $1. process_date mmddyy10.;
format id_key 1. process $1. process_date mmddyy10.;
input ID_key  x  process$    process_date;
cards;
1,1,x,01-01-15
1,2,y,02-01-15
2,1,x,03-01-15
;run;

proc transpose data=have out=tran_have(drop=_name_)  suffix=_Process_Date;
by id_key ;
id process;
var process_date ;
run;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 853 views
  • 0 likes
  • 4 in conversation