BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yesidgranadosv
Obsidian | Level 7
I need the current year and save it in a variable %let
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Are you asking for this

 

data _null_;
call symputx('Fetch_M', put(intnx ('month',today(),-2),yymmn6.) );
run;

%put Fetch_M = &Fetch_M.;

%let year=%substr( &Fetch_M.,1,4);

%let subtracted_year=%eval(&year-2);

%put &=subtracted_year;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Current year from what?

 

today()?

 

todatetime()?

 

 

 

 

yesidgranadosv
Obsidian | Level 7

/*Año y mes*/
data _null_;
call symputx('Fetch_M', put(intnx ('month',today(),-2),yymmn6.) );
run;

%put Fetch_M = &Fetch_M.;

I have the code that generates me YEAR-MONTH 

to need current year in format "2019"

novinosrin
Tourmaline | Level 20

Are you asking

 

data _null_;
call symputx('Fetch_M', put(intnx ('month',today(),-2),yymmn6.) );
run;

%put Fetch_M = &Fetch_M.;

%put year=%substr( &Fetch_M.,1,4);

 

Log
5 %put Fetch_M = &Fetch_M.;
Fetch_M = 201902
6 %put year=%substr( &Fetch_M.,1,4);
year=2019

 

 

Or in %let

 

%let year=%substr( &Fetch_M.,1,4);

%put &=year;

yesidgranadosv
Obsidian | Level 7

 

 

great!!!

%let year=%substr( &Fetch_M.,1,4);

%put &=year;

 

But if I want to subtract it 1 or 2 years ago?

 

novinosrin
Tourmaline | Level 20

Are you asking for this

 

data _null_;
call symputx('Fetch_M', put(intnx ('month',today(),-2),yymmn6.) );
run;

%put Fetch_M = &Fetch_M.;

%let year=%substr( &Fetch_M.,1,4);

%let subtracted_year=%eval(&year-2);

%put &=subtracted_year;

Reeza
Super User
%let currentYear = %sysfunc(today(), year4.);
%put &currentYear.;

 

TODAY() returns todays date. 

%SYSFUNC() takes two parameter, a SAS function (TODAY()) and the format used. YEAR4 converts it to the year.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1916 views
  • 1 like
  • 3 in conversation