04-20-2017 07:49 AM
I wanted a format for displaying year when a variable year is in 2 digits and options yearcutoff is used:
I have done a programing like below mentioned:
input v $4.;
if length(v)=2 then do;
I dont want this big code. Is there any format where i can use and can get my year value in 4 digits. Could someone help me with this.
04-20-2017 08:09 AM
date = '2000'; substr(date,4-length(strip(v))+1) = strip(v);
04-20-2017 08:11 AM
data v; input v $4.; date = '2000'; substr(date,4-length(strip(v))+1) = strip(v); datalines; 17 20 14 1 ; run; proc print data=v noobs; run;
v date 17 2017 20 2020 14 2014 1 2001
04-20-2017 08:56 AM
Sorry, how are you planning on automating a process without all the required information? A year is a four digit number YYYY, if you only have two digits YY, then you will need somehow to specify to the program what the default other two numbers are, is 17 = 1917, 1817, 1717, or 2017? That is information you have to provide as there is now other logical way of knowing what you think those two should be.
04-20-2017 09:08 AM
I am vry sorry, i have forgot to mention this , I dont want any value to be hardcoded (date='2000'). I am trying to automate the program.
You hardcoded your year with
in your initial post. What needs to be automated?
04-20-2017 09:25 AM - edited 04-20-2017 10:04 AM
So if you know that your YR2 variable is between 0 and 99 then you can just use something like this.
yr4 = year(input(put(yr2,z2.)||'0101',yymmdd6.));
Or were you looking to find an algorithm to implement the year cut off functionality yourself with using any informats?
%let yearcutoff=%sysfunc(getoption(yearcutoff)); data want ; input yr2 @@ ; yr4 = 100*((yr2<mod(&yearcutoff,100))+int(&yearcutoff/100))+yr2; yr4_date = year(input(put(yr2,z2.)||'0101',yymmdd6.)); put (_all_) (=); cards; 1 20 25 26 27 30 ;