Hi,
I am relatively new at this and always find this tricky i have fields that are like 1/7/2011 12/11/2013 etc, and they are text, how do i turn these into proper sas dates.
Thanking in advance,
Stan
I found the solution here it is:
data want;
set have;
new_date = input (date,ddmmyy10.) ;
format new_date ddmmyy10. ;
put _all_ ;
run;
Are these dates in text files or a sas dataset?
These are variables within a dataset, I've tried this:
data _null_;
a='1/7/2011';
b=input(put(a,8.),mmddyy10.);
put b/b=mmddyy10.;
run;
but that dont seem to work, any other suggestions will be greatly apreciated.
Many thanks,
Stan
data have;
input date :$10.;
_date=input(strip(date),mmddyy10.);
format _date mmddyy10.;
cards;
1/7/2011
2/19/2011
10/13/2012
12/11/2013
;
run;
sorry mate how would you do the same on the existing data set rather than the one you have created?
Many thanks,
stan
data want;
set have;
_date=input(strip(date),mmddyy10.);
format _date mmddyy10.;
run;
the strip function didnt seem to work, aim on sas 9.2
If strip() is not available use trim(left(...))
Richard
data _null_;
a='1/7/2011';
b=input(put(a,8.),mmddyy10.);
put b/b=mmddyy10.;
run;
Per slchen you would use the input function to convert text strings into numeric variables (which are what date/time variables are in SAS). The input requires you to specify the format of the data, length. So in your example your date value is 10 characters, mm/dd/yyyy, spaces are interpreted as 0. So the format to read this in would be mmddyy10. If you have only a two digit year then: mm/dd/yy, so the format is mmddyy8. The input reads in the text string and converts it to numeric SAS date which can have a format applied to it to show the date representation - otherwise you will just see a number. The reverse of course is put which takes a numeric and puts it into a character string.
Kinda looks like the same question as the just-posted https://communities.sas.com/message/215994#215994
I found the solution here it is:
data want;
set have;
new_date = input (date,ddmmyy10.) ;
format new_date ddmmyy10. ;
put _all_ ;
run;
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.