I have a 6 digit string variable which describes a date period e.g. 010111 equal too 01jan2011. My dataset also includes dates from the 20 century e.g. 010199 equal to 01jan1999.
How do I first of all convert my string variable into a sas date?
And how do I deal with the two digit year so I dont ends up with a year that looks like 2090?
data have;
input string :$6.;
datalines;
010111
010199
010180
010170
010160
010150
010140
010130
010120
;
data want;
set have;
date_num = input(string,ddmmyy6.);
format date_num yymmddd10.;
run;
proc options option=yearcutoff;
run;
Set the yearcutoff= option to a value that's appropriate for you. FYI, the last part of the log:
47 proc options option=yearcutoff;
48 run;
SAS (r) Proprietary Software Release 9.4 TS1M5
YEARCUTOFF=1926 Specifies the first year of a 100-year span that is used by date informats and functions to read a two-digit
year.
Hope your year will be from 2000 on wards. Here is one way:
data _null_;
str = '010111';
day = input(substr(str,1,2),8.);
mon = input(substr(str,3,2),8.);
year = input(cats('20',substr(str,5,2)),8.);
put day = mon = year =;
mydate = mdy(mon, day,year);
put mydate = date10.;
run;
data have;
input string :$6.;
datalines;
010111
010199
010180
010170
010160
010150
010140
010130
010120
;
data want;
set have;
date_num = input(string,ddmmyy6.);
format date_num yymmddd10.;
run;
proc options option=yearcutoff;
run;
Set the yearcutoff= option to a value that's appropriate for you. FYI, the last part of the log:
47 proc options option=yearcutoff;
48 run;
SAS (r) Proprietary Software Release 9.4 TS1M5
YEARCUTOFF=1926 Specifies the first year of a 100-year span that is used by date informats and functions to read a two-digit
year.
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss. Register now and lock in 2025 pricing—just $495!