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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
alepage
Barite | Level 11

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;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

%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.

bstarr
Quartz | Level 8

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.

alepage
Barite | Level 11

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)));

ballardw
Super User

Perhaps it is time to set

options mprint symbolgen;

run the code and post the log.

 

alepage
Barite | Level 11

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 1860 views
  • 4 likes
  • 4 in conversation