BookmarkSubscribeRSS Feed
yesidgranadosv
Obsidian | Level 7
I have this code which gives me back the date of 201601
 

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

%put Fetch_FIN = &Fetch_FIN.;

 

Could help me improve the code and other than this I need a condition with the every time it is a new year is added a year more to the result
 
I mean that when it is 2020 the result of Fetch_FIN is 2017
6 REPLIES 6
PaigeMiller
Diamond | Level 26

@yesidgranadosv wrote:
I have this code which gives me back the date of 201601
 

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

%put Fetch_FIN = &Fetch_FIN.;

 

Could help me improve the code

Improve in what way??

 

and other than this I need a condition with the every time it is a new year is added a year more to the result
 
I mean that when it is 2020 the result of Fetch_FIN is 2017
 
If I run this today (May 31, 2019), I get 201601. If I run it a year from now (May 31, 2020), I should get 201701 and in fact the code will provide the answer 201701 when run one year from today. 
 
So I don't understand the question.
--
Paige Miller
yesidgranadosv
Obsidian | Level 7

Exactly you are right... The idea is that it is a simpler code and the program would run daily and would not apply for what I want... I just wanted to express the result I want to get... 



Not how to express it in a new code much more efficient for what I want

PaigeMiller
Diamond | Level 26

Honestly, I don't understand the issue.

 

You use the word "Simpler" but the code is 4 lines, it's hard to get simpler than that.

 

You use the word "efficient" but the code runs in fractions of a second, it's hard to get more efficient than that.

--
Paige Miller
Reeza
Super User

Unfortunately your question is still unclear. 

 

Please show:

An example of what you have (variable, data set, code)

What you want as the output?

What isn't working - for example include the log or output that shows what you get. 

 


@yesidgranadosv wrote:

Exactly you are right... The idea is that it is a simpler code and the program would run daily and would not apply for what I want... I just wanted to express the result I want to get... 



Not how to express it in a new code much more efficient for what I want


 

ballardw
Super User

@yesidgranadosv wrote:
I have this code which gives me back the date of 201601
 

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

%put Fetch_FIN = &Fetch_FIN.;

 

Could help me improve the code and other than this I need a condition with the every time it is a new year is added a year more to the result
 
I mean that when it is 2020 the result of Fetch_FIN is 2017

If you are concerned about a specific interval of years then do not rely on 'month'. If you want to get the first day of the year then use an alignment value of 'B'. Example to get the beginning of the year that is 3 years prior. Note this will return the same value for ANY date in 2020. If that is not the desired output then you need to provide better examples of your input value(s) and the expected output.

data _null_;
call symputx('Fetch_FIN', put(intnx ('year','01MAR2020'd,-3,'B'),yymmn6.) );
run;

%put Fetch_FIN = &Fetch_FIN.;
data_null__
Jade | Level 19
1    %let Fetch_FIN =%sysfunc(intnx(month,%sysfunc(today()),-40),yymmn6);
2    %put NOTE: &Fetch_fin;
NOTE: 201601

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 894 views
  • 1 like
  • 5 in conversation