macro weekday

  • Follow


I worte this code in data step which worked fine but I am getting a
error when I put it in a macro. Any suggestions?

%Macro LastFriday;
* go back past 7 days to find last Friday date;

%do I = 1 %to 7;
	Fridate = ("&sysdate"d - I);
               %If weekday(Fridate) = 6 %then %do;
                      wk_day=Fridate;
               %end;
%end;
%Mend LastFriday;

Data Max;
%LastFriday;

Totlong1= 'vl_'||put(wk_dsd,YYMMDD6.);
Vaccines1= 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_vaccines';
Symptoms1= 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_symptoms';
Friday1 = put(wk_dsd,worddate18.);

/* creating macro variable under data step */
call symput("Totlong",Totlong1);
call symput("Vaccines",Vaccines1);
call symput("Symptoms",Symptoms1);
call symput("Date_Ran",Friday1);
run;

MPRINT(LASTFRIDAY):   * format wk_day YYMMDD6.;
MPRINT(LASTFRIDAY):   * go back past 7 days to find last Friday date;
MPRINT(LASTFRIDAY):   Fridate = ("21SEP11"d - I);
ERROR: Required operator not found in expression: weekday(Fridate) = 6
ERROR: The macro LASTFRIDAY will stop executing.
0
Reply jrn9 (5) 9/21/2011 9:35:19 PM

On Sep 21, 2:35=A0pm, JGE023 <j...@cdc.gov> wrote:
> I worte this code in data step which worked fine but I am getting a
> error when I put it in a macro. Any suggestions?
>
> %Macro LastFriday;
> * go back past 7 days to find last Friday date;
>
> %do I =3D 1 %to 7;
> =A0 =A0 =A0 =A0 Fridate =3D ("&sysdate"d - I);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0%If weekday(Fridate) =3D 6 %then %do;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 wk_day=3DFridate;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0%end;
> %end;
> %Mend LastFriday;
>
> Data Max;
> %LastFriday;
>
> Totlong1=3D 'vl_'||put(wk_dsd,YYMMDD6.);
> Vaccines1=3D 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_vaccines';
> Symptoms1=3D 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_symptoms';
> Friday1 =3D put(wk_dsd,worddate18.);
>
> /* creating macro variable under data step */
> call symput("Totlong",Totlong1);
> call symput("Vaccines",Vaccines1);
> call symput("Symptoms",Symptoms1);
> call symput("Date_Ran",Friday1);
> run;
>
> MPRINT(LASTFRIDAY): =A0 * format wk_day YYMMDD6.;
> MPRINT(LASTFRIDAY): =A0 * go back past 7 days to find last Friday date;
> MPRINT(LASTFRIDAY): =A0 Fridate =3D ("21SEP11"d - I);
> ERROR: Required operator not found in expression: weekday(Fridate) =3D 6
> ERROR: The macro LASTFRIDAY will stop executing.

Have you tried wrapping the fridate calc with %eval or %syseval?
0
Reply fkhurshed1 (361) 9/22/2011 3:22:14 AM


You are mixing macro code and data step code in the same macro.  Get
rid of all the internal percent signs in the macro.

Alternately, you can replace the entire kludge with a suitable call to
intnx.

On Wed, 21 Sep 2011 14:35:19 -0700 (PDT), JGE023 <jrn9@cdc.gov> wrote:

>I worte this code in data step which worked fine but I am getting a
>error when I put it in a macro. Any suggestions?
>
>%Macro LastFriday;
>* go back past 7 days to find last Friday date;
>
>%do I = 1 %to 7;
>	Fridate = ("&sysdate"d - I);
>               %If weekday(Fridate) = 6 %then %do;
>                      wk_day=Fridate;
>               %end;
>%end;
>%Mend LastFriday;
>
>Data Max;
>%LastFriday;
>
>Totlong1= 'vl_'||put(wk_dsd,YYMMDD6.);
>Vaccines1= 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_vaccines';
>Symptoms1= 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_symptoms';
>Friday1 = put(wk_dsd,worddate18.);
>
>/* creating macro variable under data step */
>call symput("Totlong",Totlong1);
>call symput("Vaccines",Vaccines1);
>call symput("Symptoms",Symptoms1);
>call symput("Date_Ran",Friday1);
>run;
>
>MPRINT(LASTFRIDAY):   * format wk_day YYMMDD6.;
>MPRINT(LASTFRIDAY):   * go back past 7 days to find last Friday date;
>MPRINT(LASTFRIDAY):   Fridate = ("21SEP11"d - I);
>ERROR: Required operator not found in expression: weekday(Fridate) = 6
>ERROR: The macro LASTFRIDAY will stop executing.

-- 
Remove del for email
0
Reply schwarzb3978 (1363) 9/22/2011 4:43:46 AM

On Sep 22, 12:43=A0am, Barry Schwarz <schwa...@dqel.com> wrote:
> You are mixing macro code and data step code in the same macro. =A0Get
> rid of all the internal percent signs in the macro.
>
> Alternately, you can replace the entire kludge with a suitable call to
> intnx.
>
>
>
>
>
> On Wed, 21 Sep 2011 14:35:19 -0700 (PDT), JGE023 <j...@cdc.gov> wrote:
> >I worte this code in data step which worked fine but I am getting a
> >error when I put it in a macro. Any suggestions?
>
> >%Macro LastFriday;
> >* go back past 7 days to find last Friday date;
>
> >%do I =3D 1 %to 7;
> > =A0 =A0Fridate =3D ("&sysdate"d - I);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 %If weekday(Fridate) =3D 6 %then %do;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0wk_day=3DFridate;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 %end;
> >%end;
> >%Mend LastFriday;
>
> >Data Max;
> >%LastFriday;
>
> >Totlong1=3D 'vl_'||put(wk_dsd,YYMMDD6.);
> >Vaccines1=3D 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_vaccines';
> >Symptoms1=3D 'bkup_'|| put(wk_dsd,YYMMDD6.)||'_symptoms';
> >Friday1 =3D put(wk_dsd,worddate18.);
>
> >/* creating macro variable under data step */
> >call symput("Totlong",Totlong1);
> >call symput("Vaccines",Vaccines1);
> >call symput("Symptoms",Symptoms1);
> >call symput("Date_Ran",Friday1);
> >run;
>
> >MPRINT(LASTFRIDAY): =A0 * format wk_day YYMMDD6.;
> >MPRINT(LASTFRIDAY): =A0 * go back past 7 days to find last Friday date;
> >MPRINT(LASTFRIDAY): =A0 Fridate =3D ("21SEP11"d - I);
> >ERROR: Required operator not found in expression: weekday(Fridate) =3D 6
> >ERROR: The macro LASTFRIDAY will stop executing.
>
> --
> Remove del for email- Hide quoted text -
>
> - Show quoted text -

Thanks, I replaced the kludge with an intnx function and work fine.
0
Reply jrn9 (5) 9/22/2011 2:52:06 PM

3 Replies
10 Views

(page loaded in 0.048 seconds)


Reply: