Hi!
I have a messy time date variable in a character string.
the orignal values look like this...
Inc |
291900MAR07 |
142300APR07 |
03APR07 |
10APR07 |
I'm creating two separate variables (date_var time_var) from the original variable (inc) In the values with the longer string the first two numbers are actually the day, and the 3-6 is the time. Many of the values do not have a time entered. What I want to do is have the time variables set to missing if the time is missing.
So, to create the date_var I did this (and it worked fine)
data want ;
set have (keep=rescuereportid inc);
inc=compress(inc);
date_var=substr(inc,1,2)||substr(inc,max(1,length(inc)-4));
run;
How can I create a time variable with variables that are different in length (i don't want to write over values that have existing time vlaues)? Want to look like this....
Orig_Var | Date_Var | Time_Var |
291900MAR07 | 29MAR07 | 1900 |
142300APR07 | 14APR07 | 2300 |
03APR07 | 03APR07 | . |
10APR07 | 10APR07 | . |
Help is appreciated!
Use the LENGTH function to check the length and then conditionally process the variables.
if length(var) = 10 then do;
time= <your code>;
date=<your code>;
end;
else if length(var)=9 then do;
time=.;
date=.input(.... );
end;
Use the LENGTH function to check the length and then conditionally process the variables.
if length(var) = 10 then do;
time= <your code>;
date=<your code>;
end;
else if length(var)=9 then do;
time=.;
date=.input(.... );
end;
@jenim514 aren't you in Ottawa, you only have a little bit left.
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.