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;

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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