DATA Step, Macro, Functions and more

Problem with macro reference

Reply
Occasional Contributor
Posts: 8

Problem with macro reference

Hello. I'm running into a problem where the first time I submit the following code, the macro MAIN is not being executed (the log is also here). However when I submit the second time it calls MAIN without a problem.

I've read things about the step boundary, but I'm curious why this does not execute the first time, but does the second. If I exit SAS and re-open again, the first time I execute the program I get the same problem again. It's only on the second and any subsequent executions that MAIN executes.

I also run into the same problem with the second set of macros being called (found in MAIN). But that takes until my third run before they execute without error.

I'm SAS 8E, if that makes a difference.

Thanks. AW

CODE:

%let path = N:\PUBLIC\PN_PA\Andy\Per Diem\SAS programs\Macro;

/*options symbolgen mlogic;*/

data _null_;
do curyear = (input(substr(put(today(), mmddyy10.),7),4.)-1) to 2005 by -1;
call symput('curyear', curyear);
call execute('%main(year=&curyear)');
end;
run;


%macro main(year=);
%do i = 2 %to 6 %by 1;
%if &i eq 1 %then %let type = driver;
%else %if &i eq 2 %then %let type = senior;
%else %if &i eq 3 %then %let type = rehab;
%else %if &i eq 4 %then %let type = ltac;
%else %if &i eq 5 %then %let type = snf;
%else %if &i eq 6 %then %let type = acute;
%else %put 'Error in Main Macro process - variable TYPE did not resolve';
%&type(year=&year,type=&type);
%include "&path.\&type..sas";
%end;
%mend main;

LOG (first execution):

1
2 %let path = N:\PUBLIC\PN_PA\Andy\Per Diem\SAS programs\Macro;
3
4 /*options symbolgen mlogic;*/
5
6 data _null_;
7 do curyear = (input(substr(put(today(), mmddyy10.),7),4.)-1) to 2005 by -1;

8 call symput('curyear', curyear);
9 call execute('%main(year=&curyear)');
10 end;
11 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
8:24
WARNING: Apparent invocation of macro MAIN not resolved.
WARNING: Apparent invocation of macro MAIN not resolved.
WARNING: Apparent invocation of macro MAIN not resolved.
WARNING: Apparent invocation of macro MAIN not resolved.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds


NOTE: CALL EXECUTE generated line.
WARNING: Apparent invocation of macro MAIN not resolved.
WARNING: Apparent invocation of macro MAIN not resolved.
WARNING: Apparent invocation of macro MAIN not resolved.
WARNING: Apparent invocation of macro MAIN not resolved.
NOTE: Line generated by the CALL EXECUTE routine.
1 + %main(year= 2008)
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

2 + %main(year= 2007)
3 + %main(year= 2006)
4 + %main(year= 2005)
12
13
14 %macro main(year=);
15 %do i = 2 %to 6 %by 1;
16 %if &i eq 1 %then %let type = driver;
17 %else %if &i eq 2 %then %let type = senior;
18 %else %if &i eq 3 %then %let type = rehab;
19 %else %if &i eq 4 %then %let type = ltac;
20 %else %if &i eq 5 %then %let type = snf;
21 %else %if &i eq 6 %then %let type = acute;
22 %else %put 'Error in Main Macro process - variable TYPE did not resolve';

23 %&type(year=&year,type=&type);
24 %include "&path.\&type..sas";
25 %end;
26 %mend main;


LOG (second execution):

27
28 %let path = N:\PUBLIC\PN_PA\Andy\Per Diem\SAS programs\Macro;
29
30 /*options symbolgen mlogic;*/
31
32 data _null_;
33 do curyear = (input(substr(put(today(), mmddyy10.),7),4.)-1) to 2005 by -1;

34 call symput('curyear', curyear);
35 call execute('%main(year=&curyear)');
36 end;
37 run;

NOTE: Numeric values have been converted to character values at the places given by:
(Line)Smiley SadColumn).
34:24
WARNING: Apparent invocation of macro SENIOR not resolved.
WARNING: Apparent invocation of macro REHAB not resolved.
WARNING: Apparent invocation of macro LTAC not resolved.
WARNING: Apparent invocation of macro SNF not resolved.
WARNING: Apparent invocation of macro ACUTE not resolved.
WARNING: Apparent invocation of macro SENIOR not resolved.
WARNING: Apparent invocation of macro REHAB not resolved.
WARNING: Apparent invocation of macro LTAC not resolved.
WARNING: Apparent invocation of macro SNF not resolved.
WARNING: Apparent invocation of macro ACUTE not resolved.
WARNING: Apparent invocation of macro SENIOR not resolved.
WARNING: Apparent invocation of macro REHAB not resolved.
WARNING: Apparent invocation of macro LTAC not resolved.
WARNING: Apparent invocation of macro SNF not resolved.
WARNING: Apparent invocation of macro ACUTE not resolved.
WARNING: Apparent invocation of macro SENIOR not resolved.
WARNING: Apparent invocation of macro REHAB not resolved.
WARNING: Apparent invocation of macro LTAC not resolved.
WARNING: Apparent invocation of macro SNF not resolved.
WARNING: Apparent invocation of macro ACUTE not resolved.
NOTE: DATA statement used:
real time 0.03 seconds
cpu time 0.03 seconds


NOTE: CALL EXECUTE generated line.
WARNING: Apparent invocation of macro SENIOR not resolved.
NOTE: Line generated by the CALL EXECUTE routine.
1 + %senior(year=2008,type=senior);
-
180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: Line generated by the CALL EXECUTE routine.
1 + %senior(year=2008,type=senior); %include "N:\PUBLIC\PN_PA\Andy\Per Diem\SAS
1 !+programs\Macro\senior.sas"; %rehab(year=2008,type=rehab); %include
-
180
1 !+"N:\PUBLIC\PN_PA\Andy\Per Diem\SAS programs\Macro\rehab.sas"; %ltac(year=2008,type=ltac);
1 !+%include
ERROR 180-322: Statement is not valid or it is used out of proper order.
.
.
.
...same type of log data is created for each
Occasional Contributor
Posts: 8

Re: Problem with macro reference

It looks like I've found the answer to my problem. Since the macros were not in WORK.SASMACR they could not be found by the call intially. However the first time the program was run it created a compiled version in WORK.SASMACR.

I was able to get this to work by creating compiled versions of each of the macros in a directory that I specify and then use in OPTIONS MSTORE SASMSTORE =.

The given macro needs to be run once in order to be compiled. Once it is compiled SAS can find the macro that is being called.
Trusted Advisor
Posts: 2,115

Re: Problem with macro reference

If you want to use a macro without the extra step of a compiled library, just put the definition of the macro before it's first invocation.
Ask a Question
Discussion stats
  • 2 replies
  • 182 views
  • 0 likes
  • 2 in conversation