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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.