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;
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
;
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
;
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.
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;
Hi Loko,
Can you please elaborate _infile_,i+2*(i-1),2 a little bit more?
I would be greatly appreciate it.
Thank you.
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.
I believe this is an example of how YEARCUTOFF works, in which case 11 becomes 2011 because of the OPTIONS YEARCUTOFF=1910;
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.
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.