BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
santhosh
Fluorite | Level 6

Hi,

I am trying to create macros based on month

eg., if month is JAN FEB MAR then i need to  create year macro -1 year

else i want to create macro +1 year

if Month JAN/FEB/MAR 2012 then i want to create macro year 2011

else i want to create macro year 2012

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
%let day='02jul2012'd ;

options minoperator;
%macro  a;
%if %sysfunc(substr(%sysfunc(putn(&day,monyy.)),1,3)) in JAN FEB MAR %then 
 %do;data _null_;call symputx('year',year(&day)-1);stop;run;%end;
 %else %do;data _null_;call symputx('year',year(&day));stop;run;%end;
%mend a;
%a
%put &year ;


Ksharp

View solution in original post

11 REPLIES 11
manojinpec
Obsidian | Level 7

Hi,

i the macro value (+1 year)  (-1year) like that?

Thanks & Regards,

Manoj

santhosh
Fluorite | Level 6

yes

Creating macro year based on months conditionally

if month is JAN/FEB/MAR 2012 then want to create macro year=2011

else macro year=2012

Haikuo
Onyx | Level 15

And if the 'date'  goes with your system time dynamically,  you don't need to feed it:

data _null_;

if month(date()) in (1,2,3) then

call symputx('year',year(date())-1);

else call symputx('year',year(date()));

run;

%put &year;

Regards,

Haikuo

santhosh
Fluorite | Level 6

Thanks for support

can we select the date insted of system date the report can be generated for any month the date should vary

march to march

Ksharp
Super User
%let day='02jul2012'd ;

options minoperator;
%macro  a;
%if %sysfunc(substr(%sysfunc(putn(&day,monyy.)),1,3)) in JAN FEB MAR %then 
 %do;data _null_;call symputx('year',year(&day)-1);stop;run;%end;
 %else %do;data _null_;call symputx('year',year(&day));stop;run;%end;
%mend a;
%a
%put &year ;


Ksharp

santhosh
Fluorite | Level 6

Thanks Ksharp

it is working fine

title of program is report generated for the period 31 Dec 2011 for financial year 2011-2012

(if month is from april 2011 to march 2012)

if month is April 2012 then title will be " for financial year 2012-2013"

i am unable to put other date

Haikuo
Onyx | Level 15

Data _null_'s code will for you then.

data_null__
Jade | Level 19

Shifted interval...

29   %let day='02jul2012'd ;

30   %let year=%sysfunc(intnx(Year1.4,&day,0),year.);

31   %put YEAR=&YEAR;

YEAR=2012

35   %let day='02feb2012'd ;

36   %let year=%sysfunc(intnx(Year1.4,&day,0),year.);

37   %put YEAR=&YEAR;

YEAR=2011

santhosh
Fluorite | Level 6

Thanks for  your support

i want to generate a title

if the report generating period is form April 2011 to Mar2012 then title=

"for the financial year 2011 to 2012"

if the report is generating for period dec 2011 then title will be "for the financial year 2011-2012"

if the report is generating for period jan 2012 then title will be " for the financial year 2011-2012"

Haikuo
Onyx | Level 15

I maybe misunderstand your question, but could it be done by just  using the title statement?

Supposely you have already run _null_'s code:

Title "for the financial year &year.- %eval(&year.+1)";

Haikuo

data_null__
Jade | Level 19

How about this.

38   %let day='02feb2012'd ;

39   %let year=%sysfunc(intnx(Year1.4,&day,0,B),year.)-%sysfunc(intnx(Year1.4,&day,0,E),year.);;

40   %put YEAR=&YEAR;

YEAR=2011-2012

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1956 views
  • 0 likes
  • 5 in conversation