Desktop productivity for business analysts and programmers

how to transform a numerical date into date9. format using %sysfunc?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 111
Accepted Solution

how to transform a numerical date into date9. format using %sysfunc?

This code works perfectly with EG 7.15 but on the robot   (SAS version ????)

 

%let sysyear= %sysfunc(year("&sysdate"d));
%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)));
%put &sysyear;
%put &annee;
%put &firstwday;
%put &firstworkingday;

 

1229 +%let sysyear= %sysfunc(year("&sysdate"d));
Le Système SAS

1230 +
1231 + %if &MotifRapport EQ FINANCIER %THEN
1232 + %DO;
1233 + %let Annee=&sysyear;
1234 + %let FirstWDay=%sysfunc(NWKDOM(1,2,1,&Annee));
1235 + %let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, z8.), date9.);
1236 + %let Debut=%sysfunc(compress(%bquote('&FirstWorkingDay'd)));
1237 + %END;
1238 + %ELSE
1239 + %DO;
1240 + %let Annee=%eval(&sysyear-1);
1241 + %let Debut=%sysfunc(compress(%BQUOTE('31OCT&Annee.'D)));
1242 + %END;
1243 +RUN;
1244 +%mend MotifRap;
1245 +%MotifRap;
MLOGIC(MOTIFRAP): Début de l'exécution.
MLOGIC(MOTIFRAP) : %GLOBAL ANNEE FIRSTWDAY FIRSTWORKINGDAY DEBUT
MLOGIC(MOTIFRAP) : %LET (le nom de la variable est SYSYEAR)
SYMBOLGEN: La macro-variable SYSDATE est résolue en 05JAN18
SYMBOLGEN: La macro-variable MOTIFRAPPORT est résolue en FINANCIER
MLOGIC(MOTIFRAP) : La condition %IF &MotifRapport EQ FINANCIER est TRUE
MLOGIC(MOTIFRAP) : %LET (le nom de la variable est ANNEE)
SYMBOLGEN: La macro-variable SYSYEAR est résolue en 2018
MLOGIC(MOTIFRAP) : %LET (le nom de la variable est FIRSTWDAY)
SYMBOLGEN: La macro-variable ANNEE est résolue en 2018
MLOGIC(MOTIFRAP) : %LET (le nom de la variable est FIRSTWORKINGDAY)
SYMBOLGEN: La macro-variable FIRSTWDAY est résolue en 21185
WARNING: Argument 2 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value.
MLOGIC(MOTIFRAP) : %LET (le nom de la variable est DEBUT)
SYMBOLGEN: La macro-variable FIRSTWORKINGDAY est résolue en .
MPRINT(MOTIFRAP): RUN;
MLOGIC(MOTIFRAP) : Fin de l'exécution.
1246 +%put &Annee;
SYMBOLGEN: La macro-variable ANNEE est résolue en 2018
2018
1247 +%put &FirstWDay;

 

Any idea how to solve this issue.  It is like the SAS on the robot does not recognize 

 

%let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, z8.), date9.);

 

 


Accepted Solutions
Solution
‎01-08-2018 01:53 PM
Super User
Posts: 6,544

Re: how to transform a numerical date into date9. format using %sysfunc?

One possibility, although I can't tell you why it would work in some cases but not others ...

 

There is no such thing as a z8 informat.  The "z" family is a set of formats, not informats.  Try switching to this informat instead:

 

8.

 

 

View solution in original post


All Replies
Super User
Super User
Posts: 9,227

Re: how to transform a numerical date into date9. format using %sysfunc?

[ Edited ]

Sorry, can't even look much at that.  I got to %sysfunc(year("&sysdate"d)); and wonder what on earth you are doing.  You seem to understand that %sysfunc() can call functions, and still these are put ino macro variables?  Surely that is just duplicating the data, i.e. you have a perfectly good function, and also the result of function.  The year also returns a number, but you then put it into a text variable (macro is always text), and then duplicate that information in Annee.  You would make your life so much easier using Base SAS to do data manipulations, and call functions when needed rather than storing duplicates of duplicates.

data _null_;
call symput('debut',put(nwkdom(1,2,1,year(today())),date9.));
run;

%put &debut.;

 

Solution
‎01-08-2018 01:53 PM
Super User
Posts: 6,544

Re: how to transform a numerical date into date9. format using %sysfunc?

One possibility, although I can't tell you why it would work in some cases but not others ...

 

There is no such thing as a z8 informat.  The "z" family is a set of formats, not informats.  Try switching to this informat instead:

 

8.

 

 

Frequent Contributor
Posts: 111

Re: how to transform a numerical date into date9. format using %sysfunc?

Posted in reply to Astounding

Hello, 

 

As you have suggested, I have use the following code and it works!

Thanks a lot for your help.

 

%let sysyear= %sysfunc(year("&sysdate"d));
%let Annee=&sysyear;
%let FirstWDay=%sysfunc(NWKDOM(1,2,1,&Annee));
%let FirstWorkingDay=%sysfunc(inputn(&FirstWDay, 8.), date9.);
%let Debut=%sysfunc(compress(%bquote('&FirstWorkingDay'd)));
%put &sysyear;
%put &annee;
%put &firstwday;
%put &firstworkingday;

Super User
Posts: 13,084

Re: how to transform a numerical date into date9. format using %sysfunc?

Any idea how to solve this issue.  It is like the SAS on the robot does not recognize 

 What robot?

 

If the purpose of this code is to generate values used by a SAS program often it is more stable to either generate the date values such as 20810 (numeric) instead of '01JAN2017'd as having quotes in the macro values often leads to ugly quote around dealing with quotes. Or if you have a need to see 01Jan2017 then have that as the macro variable and when you need to use the SAS date value then "&datemacrovar"d

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 225 views
  • 1 like
  • 4 in conversation