Hello, based on the type of report (operational or financial) I am trying to get the good starting date (see below)
For an operational report, the starting date (debut) should be equal to '02jan2017'd;
For a financial report, the starting date (Debut) should be equal to '31oct2016'd;
Here's my code below but It does work and I don’t know Why.
Does someone could help me with that issue?
%let motifrap=FINANCIER;
*%let MotifRap=OPERATIONNEL;
%let sysyear= %sysfunc(year("&sysdate"d));
%MACRO MotifRap;
%if &motifrap EQ "FINANCIER" %THEN
%DO;
%let Annee=&sysyear;
%let FirstWDay=%sysfunc(NWKDOM(1,2,1,&Annee));
%let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, z8.), date9.);
%let Debut=%sysfunc(compress(%bquote('&FirstWorkingDay'd)));
%END;
%ELSE
%DO;
%let Annee=%eval(&sysyear-1);
%let Debut=%sysfunc(compress(%BQUOTE('31OCT&Annee.'D)));
%END;
RUN;
%mend MotifRap;
%MotifRap;
%put &Annee;
%put &FirstWDay;
%put &FirstWorkingDay;
%put &Debut;
%put &motifrap;
I have found a solution...
Here's the code that is working
/*options mprint symbolgen;*/
%MACRO MotifRap;
%global Annee FirstWday FirstWorkingDay Debut;
%let sysyear= %sysfunc(year("&sysdate"d));
%if &MotifRapport EQ FINANCIER %THEN
%DO;
%let Annee=&sysyear;
%let FirstWDay=%sysfunc(NWKDOM(1,2,1,&Annee));
%let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, z8.), date9.);
%let Debut=%sysfunc(compress(%bquote('&FirstWorkingDay'd)));
%END;
%ELSE
%DO;
%let Annee=%eval(&sysyear-1);
%let Debut=%sysfunc(compress(%BQUOTE('31OCT&Annee.'D)));
%END;
RUN;
%mend MotifRap;
%let MotifRapport = FINANCIER;
%put &MotifRapport;
%MotifRap;
%put &Annee &FirstWDay &FirstWorkingDay &Debut;
%let MotifRapport = OPERATIONAL;
%put &MotifRapport;
%MotifRap;
%put &Annee &Debut;
%I CaNTRea% th
IS code.
Try looking at other questions posted here for how to format code and use the {i} code window above the post are to show code with formatting preserved.
%let motifrap=FINANCIER;
data _null_;
if "&motifrap."="FINANCIER" then
call symput('debut',put(nwkdom(1,2,1,year(today())),date9.));
else call symput('debut',cats("31OCT",year(today())));
run;
%put &debut.;
Would be one example of simplifying that code.
One reason is in your %if/%then:
%if &motifrap EQ "FINANCIER" %THEN
&motifrap = FINANCIER (without quotes), not "FINANCIER" (with quotes). So you need either:
"&motifrap" eq "FINANCIER, or &motifrap = FINANCIER.
I have tried both but it seems that it does not recognize:
%let FirstWDay=%sysfunc(NWKDOM(1,2,1,&Annee));
%let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, z8.), date9.);
%let Debut=%sysfunc(compress(%bquote('&FirstWorkingDay'd)));
Perhaps it is time to set
options mprint symbolgen;
run the code and post the log.
I have found a solution...
Here's the code that is working
/*options mprint symbolgen;*/
%MACRO MotifRap;
%global Annee FirstWday FirstWorkingDay Debut;
%let sysyear= %sysfunc(year("&sysdate"d));
%if &MotifRapport EQ FINANCIER %THEN
%DO;
%let Annee=&sysyear;
%let FirstWDay=%sysfunc(NWKDOM(1,2,1,&Annee));
%let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, z8.), date9.);
%let Debut=%sysfunc(compress(%bquote('&FirstWorkingDay'd)));
%END;
%ELSE
%DO;
%let Annee=%eval(&sysyear-1);
%let Debut=%sysfunc(compress(%BQUOTE('31OCT&Annee.'D)));
%END;
RUN;
%mend MotifRap;
%let MotifRapport = FINANCIER;
%put &MotifRapport;
%MotifRap;
%put &Annee &FirstWDay &FirstWorkingDay &Debut;
%let MotifRapport = OPERATIONAL;
%put &MotifRapport;
%MotifRap;
%put &Annee &Debut;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.