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.
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.
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.