I've got a data set where, for one reason or another, one of the date variables is coming in as a character variable. Missing variables are blank, dates are present as things like 01-Nov-08. I need these in the proper SAS days-since-1/1/1960 format.
I've tried using %sysfunc, but I can't seem to get it to cooperate. Any chance someone can point me in the right direction?
You can use function input to get that.
num_date=input(char_date,date12.);
format num_date mmddyy12.;
Ksharp
You can use function input to get that.
num_date=input(char_date,date12.);
format num_date mmddyy12.;
Ksharp
Hi Ksharp,
Is it the only way to do?
Cheers.
You don't say how you are reading the data but when you indicate " for one reason or another, one of the date variables is coming in as a character variable" I suspect proc import.
Proc Import uses lots of defaults and limited information from the source data. You might be able to write a datastep to read the data source and apply an informat at that time, but without details of the source data this is a guess.
What do you mean ?
proc format;
invalue $fmt
'Nov'=11
'Dec'=12
.........
;
run;
num_date=mdy(
input(scan(char_date,'-',2),$fmt.),
input(scan(char_date,'-',1),best8.),
input(scan(char_date,'-',-1),best8.);
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.