BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
frakje
Calcite | Level 5

Hello

 

I'm new to SAS !

 

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?

 

Kind regards Frank

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
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.

View solution in original post

2 REPLIES 2
KachiM
Rhodochrosite | Level 12

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;

 

Kurt_Bremser
Super User
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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 637 views
  • 0 likes
  • 3 in conversation