Hi all,
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:
data v;
input v $4.;
datalines;
17
20
14
1
;
run;
option yearcutoff=2000;
data v1(drop=catv);
set v;
if length(v)=2 then do;
catv= input("01/01/"||strip(v),ddmmyy8.);
date=year(catv);
end;
end;
run;
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.
Many Thanks
date = '2000';
substr(date,4-length(strip(v))+1) = strip(v);
Example:
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;
Result:
v date 17 2017 20 2020 14 2014 1 2001
Hi,
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.
Many Thanks.
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.
@navyaroopa wrote:
Hi,
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.
Many Thanks.
You hardcoded your year with
option yearcutoff=2000;
in your initial post. What needs to be automated?
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
;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.