Hello!
Can someone please help me
I have created a program where I have automated dates till reporting month. Reporting month is one month prior to the current month. Suppose current month is July
I have used
%do i=1 %to &month ;
month macro variable i have declared till previous month which is coming 6 and used the do loop which is fetching me right results from jan to june this year. The issue is in certain case if the user wants to have reporting month as May or april, how do I do that? this macro variable and macro is used at more than 100 places i can't go and change this everytime...I need some function or macro variable where it should take today() as previous month date or 2 months date prior to current month ... is it possible to define today() to previous month in macro variable.. That will solve my concern.
@sameer112217 wrote:
Hello!
Can someone please help me
I have created a program where I have automated dates till reporting month. Reporting month is one month prior to the current month. Suppose current month is July
I have used
%do i=1 %to &month ;
%let date2=%sysfunc(intnx(month, %sysfunc(today()),-&i.,e), date9.);"&date2"n %end;
month macro variable i have declared till previous month which is coming 6 and used the do loop which is fetching me right results from jan to june this year. The issue is in certain case if the user wants to have reporting month as May or april, how do I do that? this macro variable and macro is used at more than 100 places i can't go and change this everytime...I need some function or macro variable where it should take today() as previous month date or 2 months date prior to current month ... is it possible to define today() to previous month in macro variable.. That will solve my concern.
Which macro variable? Month? Date2? Something else?
Are the "100 places" in one macro? many macros?
And I can't say that I have ever been happy with variables with names like "31JAN2017"n at that is usually and indication of poor data structure to begin with.
You might consider adding a keyword parameter to your macro calls that would conditionally override which ever bit of code you are concerned with and set the value of the date(?) variable.
The whole situation is not very clear to me.
I hope one of the two codes can help you:
data _null_;
td = today();
/* -1- */
end_last_manth = td - day(td);
/* -2- */
end_last_month = intbx('month',td,-1,'e');
call symput('date2', put(end_last_month, ...desired format ...);
run;
Today() cannot be changed - otherwise it would become useless. If you need a bit of text which is the month before today(), then set a macro varible with the information and use that throughout your code - this is the purpose of macro variables.
It looks like you count backwards from month to the beginning of the year.
Try reversing that loop count so that you can start at the beginning of the period and count forward, it shouldn't require any other changes in your code.
%do i=&month %to 1 %by -1;
@sameer112217 wrote:
Hello!
Can someone please help me
I have created a program where I have automated dates till reporting month. Reporting month is one month prior to the current month. Suppose current month is July
I have used
%do i=1 %to &month ;
%let date2=%sysfunc(intnx(month, %sysfunc(today()),-&i.,e), date9.);"&date2"n %end;
month macro variable i have declared till previous month which is coming 6 and used the do loop which is fetching me right results from jan to june this year. The issue is in certain case if the user wants to have reporting month as May or april, how do I do that? this macro variable and macro is used at more than 100 places i can't go and change this everytime...I need some function or macro variable where it should take today() as previous month date or 2 months date prior to current month ... is it possible to define today() to previous month in macro variable.. That will solve my concern.
Which macro variable? Month? Date2? Something else?
Are the "100 places" in one macro? many macros?
And I can't say that I have ever been happy with variables with names like "31JAN2017"n at that is usually and indication of poor data structure to begin with.
You might consider adding a keyword parameter to your macro calls that would conditionally override which ever bit of code you are concerned with and set the value of the date(?) variable.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.