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; 

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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