Hi! I have compressed date/time variables in a character string with values that now look like this:
312140AUG07
311415MAY08
092105MAR07
The first two numbers are the day(date). 3-6 is the time. THen month and year....
I would like it to look like this format DDMMMYY:HHMM
What I am doing is not working. Appreciate your help!!
data rr.datetime2006 (keep=Inc Alert Launch OnSce Locate Recov Deliv RTB);
set rr2006labels;
array change _character_;
do over change;
change=compress(change,'');
day=substr(change,1,2);
time=substr(change,3,4);
month=substr(change,7,3);
year=substr (10,2);
date=catt(day,month,year);
change=catt(date,time); *want this to look like DDMMMYY:HHMM;
end;
run;
Presumably, you have thought this through and it would be satisfactory to keep the time of day but get rid of the day itself. In any case, you need just one statement in your DO OVER loop:
change = substr(change, 7, 5) || ':' || substr(change, 3, 4);
Presumably, you have thought this through and it would be satisfactory to keep the time of day but get rid of the day itself. In any case, you need just one statement in your DO OVER loop:
change = substr(change, 7, 5) || ':' || substr(change, 3, 4);
@astounding I do need to keep the day in this. I see what your saying though - correction I need the end format to be DDMMMYY:HHMM. But even removing the day- i received an error in your code (Invalid third argument to function SUBSTR)
The code is correct. I suspect that _CHARACTER_ is incorrect and includes some character variables that contain fewer than 12 characters. If that's the case, you might have to replace _CHARACTER_ with a list of just the appropriate variable names.
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.
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.