I am not sure what you are asking for. Your WANT looks like multiple variables for month, but that does not make sense if concatenating. The following concatenates the DATENUM values into one long character string.
data have;
input Id Release_date :mmddyy8. Datenum;
datalines;
1 03/02/11 1245
2 01/01/11 3423
2 01/10/11 5432
run;
proc sort data=have;
by id release_date;
run;
data want(keep=id monthnum);
set have;
by id;
length monthnum $40;
retain monthnum ;
if first.id then monthnum=' ';
monthnum=cats(monthnum,datenum);
if last.id then output want;
run;
If you actually want the values in separate variables you may want to do a PROC TRANSPOSE.
Malena,
I I understand you correctly, you want something like this:
data have; input Id Release_date :mmddyy8. Datenum; datalines; 1 03/02/11 1245 2 01/01/11 3423 2 01/10/11 5432 run; proc sort data=have; by id Release_date; run; Data want; do until(last.id); set have; by id; array months (0:23) $20 month1-month24; if first.id then date0=Release_date; idx=intck('month',Release_date,date0); if idx>23 then
Error 'Date out of range, more than 24 months since first release!'; else
call cats(months(idx),Datenum); end; drop Release_date date0 idx; run;
A couple of notes:
Instead of adding 1 to the array index IDX in every calculation, I zero-based the array (using (0:23) in the array definition). So, in the actual datastep, the month[0] is the month1 variable, etc.
I put in a check for array index out of range, just in case. SAS would also throws an errror message if you referenced the array with an index larger than 24, but I think it is better to get a reasonable informative error message.
Regards,
Søren
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!
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.
Ready to level-up your skills? Choose your own adventure.