Desktop productivity for business analysts and programmers

Trying to get the good starting date based on the type of report

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

Trying to get the good starting date based on the type of report

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;

 


Accepted Solutions
Solution
‎12-15-2017 09:16 AM
Regular Contributor
Posts: 168

Re: Trying to get the good starting date based on the type of report

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


All Replies
Super User
Super User
Posts: 9,840

Re: Trying to get the good starting date based on the type of report

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

Contributor
Posts: 30

Re: Trying to get the good starting date based on the type of report

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.

Regular Contributor
Posts: 168

Re: Trying to get the good starting date based on the type of report

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

Super User
Posts: 13,941

Re: Trying to get the good starting date based on the type of report

Perhaps it is time to set

options mprint symbolgen;

run the code and post the log.

 

Solution
‎12-15-2017 09:16 AM
Regular Contributor
Posts: 168

Re: Trying to get the good starting date based on the type of report

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 181 views
  • 4 likes
  • 4 in conversation