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

Hi guys,

                                                                     01/01/11                                      2001 2001 1911

I'm trying to resolve the raw data(left data set)   02/23/05     to (right data set)         2002 1923 2005

                                                                     03/15/15                                      2003 1915 1915

                                                                     05/09/06                                      2005 2009 2006

Below is my code:

options yearcutoff=1910;

data range;

infile datalines dlm='/';

input year1: yy4.

      year2: yy4.                    How to informat year to make a 2-digit year to be a 4-digit year? Thank you in advance.

      year3: yy4.;

datalines;

01/01/11

02/23/05

03/15/15

05/09/06

;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

options yearcutoff=1910;

data range (drop=i);

  infile datalines dlm='/';

  format date1-date3 date9.;

  array dates(*) date1-date3;

  array years(3) year1-year3;

  input date1-date3;

  do i=1 to 3;

    dates(i)=mdy(1,1,dates(i));

    years(i)=year(dates(i));

  end;

datalines;

01/01/11

02/23/05

03/15/15

05/09/06

;

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

options yearcutoff=1910;

data range (drop=i);

  infile datalines dlm='/';

  format date1-date3 date9.;

  array dates(*) date1-date3;

  array years(3) year1-year3;

  input date1-date3;

  do i=1 to 3;

    dates(i)=mdy(1,1,dates(i));

    years(i)=year(dates(i));

  end;

datalines;

01/01/11

02/23/05

03/15/15

05/09/06

;

jakarman
Barite | Level 11

Chouchou you are learning, I know. This question is meant to get you aware of several things.

1/ dates in SAS are not bound by digits it is only using the number of days since 1jan1960.

2/ reading years / dates wit a two digit / four digit the famous millennium bug (no real bug) is having a sliding window (options yearcutoff). With that the fourdigit expansion

3/ with a delimited file you can specify a length with formats, mostly the length is ignored.

known and conversions (inpt) are implied done.
Run the code to verify this behavior.  

---->-- ja karman --<-----
Loko
Barite | Level 11

Hello,

Another solution:

data range;

infile datalines ;
input ;

array year{3};

do i=1 to 3;
year{i}=put(mdy(1,1,substr(_infile_,i+2*(i-1),2)),year4.);
end;


datalines;
01/01/11
02/23/05
03/15/15
05/09/06
;

drop i;
run;

chouchou
Calcite | Level 5

Hi Loko,

Can you please elaborate  _infile_,i+2*(i-1),2 a little bit more?

I would be greatly appreciate it.

Thank you.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I think its a bit dangerous, for instance your test data:

01/01/11                                      2001 2001 1911

What makes 01 be 2001, and 11 be 1911?  Surely it could as easily be 2011.  I would check the souce (raw data) and fix that.  E.g. if from database is there a spec which details what that data is, if Excel check back with person sending it and ask them to provide full information etc.

data_null__
Jade | Level 19

I believe this is an example of how YEARCUTOFF works,  in which case 11 becomes 2011 because of the OPTIONS YEARCUTOFF=1910; 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4813 views
  • 8 likes
  • 6 in conversation