DATA Step, Macro, Functions and more

SAS Macro in Nested Do Loop "Line generated by the macro variable" error

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

SAS Macro in Nested Do Loop "Line generated by the macro variable" error

Hi all,

I'm using SAS on Unix, that's the reason for the line numbers on the side. I'm using a nested do loop in macro and the code is giving me a couple unexpected lines right at the end. I'm not sure where they're coming from, but apparently my first counter variable, i, is causing a couple extra lines to generate, which is messing with the execution, causing the observations to be zero in my output dataset. The data files themselves should be fine and I don't believe that's the issue. Anybody got any ideas what might be causing the extra couple lines?

Thanks,
Mike, do

1009  /*create variables*/
1010  libname in "/work/mg/AutomationTest";

NOTE: Libname IN refers to the same physical library as EX.

NOTE: Libref IN was successfully assigned as follows:

Engine:   V9
Physical Name: /work/mg/AutomationTest

1011

1012  %let nummodeled = 3;
1013  %let numg = 4;
1014  %macro addAO;
1015  data in.fact_prelog;
1016  set in.fact_acv;
1017  %do i = 1 %to &nummodeled;
1018  BASEUNITSAO&i = 0;
1019  EQBASEVOLAO&i = 0;
1020  EQVOLAO&i= 0;
1021  UNITSAO&i= 0;
1022  DOLAO&i= 0;
1023  BASEDOLAO&i= 0;
1024  featall_bvolAO&i= 0;
1025  feat_bvolAO&i= 0;
1026  fandd_bvolAO&i= 0;
1027  disp_bvolAO&i= 0;
1028  %do j = 1 %to &numg;
1029  BASEUNITSAO&i = BASEUNITSAO&i + BASEUNITS&j;
1030  EQBASEVOLAO&i = EQBASEVOLAO&i + EQBASEVOL&j;
1031  EQVOLAO&i = EQVOLAO&i + EQVOL&j;
1032  UNITSAO&i = UNITSAO&i + UNITS&j;
1033  DOLAO&i = DOLAO&i + DOL&j;
1034  BASEDOLAO&i = BASEDOLAO&i + BASEDOL&j;
1035  featall_bvolAO&i = featall_bvolAO&i + featall_bvol&j;
1036  feat_bvolAO&i = feat_bvolAO&i + feat_bvol&j;
1037  fandd_bvolAO&i = fandd_bvolAO&i + fandd_bvol&j;
1038  disp_bvolAO&i = disp_bvolAO&i + disp_bvol&j;
1039  %end;
^L37                                                    The SAS System                        17:36 Tuesday, August 21, 2012

1040  BASEUNITSAO&i = BASEUNITSAO&i - BASEUNITS&i;
1041  EQBASEVOLAO&i = EQBASEVOLAO&i - EQBASEVOL&i;
1042  EQVOLAO&i = EQVOLAO&i - EQVOL&i;
1043  UNITSAO&i = UNITSAO&i - UNITS&i;
1044  DOLAO&i = DOLAO&i - DOL&i;
1045  BASEDOLAO&i = BASEDOLAO&i - BASEDOL&i;
1046  featall_bvolAO&i = featall_bvolAO&i - featall_bvol&i;
1047  feat_bvolAO&i = feat_bvolAO&i - feat_bvol&i;
1048  fandd_bvolAO&i = fandd_bvolAO&i - fandd_bvol&i;
1049  disp_bvolAO&i = disp_bvolAO&i - disp_bvol&i;
1050  PRICEAO&i = DOLAO&i/EQVOLAO&i;
1051  EQREGPRICEAO&i = BASEDOLAO&i/EQBASEVOLAO&i;
1052  pct_featallAO&i = featall_bvolAO&i/EQBASEVOLAO&i;
1053  pct_featAO&i = feat_bvolAO&i/EQBASEVOLAO&i;
1054  pct_fanddAO&i = fandd_bvolAO&i/EQBASEVOLAO&i;
1055  pct_dispAO&i = disp_bvolAO&i/EQBASEVOLAO&i;
1056  PROMOPRICEAO&i = PRICE AO&i/ EQREGPRICEAO&i;
1057  %end;

1058

1059  %mend addAO;

1060

1061  %addAO;

NOTE: Line generated by the macro variable "I".

1061   AO1
___
22

NOTE: Line generated by the macro variable "I".

1061   AO2
___
22

NOTE: Line generated by the macro variable "I".

1061   AO3
___
22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,

LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=, {, |, ||, ~=.

1062  run;

NOTE: The SAS System stopped processing this step because of errors.

NOTE: SAS set option OBS=0 and will continue to check statements. This may cause NOTE: No observations in data set.

WARNING: The data set IN.FACT_PRELOG may be incomplete.  When this step was stopped there were 0 observations and 143 variables.

WARNING: Data set IN.FACT_PRELOG was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time      0.03 seconds
cpu time       0.02 seconds

Accepted Solutions
Solution
‎08-21-2012 07:25 PM
Super User
Super User
Posts: 7,039

Re: SAS Macro in Nested Do Loop "Line generated by the macro variable" error

You appear to have an extra space in the middle of one of statements.

Between the E and A in PRICEAO&i

PROMOPRICEAO&i = PRICE AO&i/ EQREGPRICEAO&i;

View solution in original post


All Replies
Super User
Posts: 19,770

Re: SAS Macro in Nested Do Loop "Line generated by the macro variable" error

This is a great example of where to not use macros. Use an array instead.

Its weird to see the SAS title in the middle of your code like that. Is this from the LOG directly?

New Contributor
Posts: 3

Re: SAS Macro in Nested Do Loop "Line generated by the macro variable" error

yeah I posted the log directly in. I don't know how to use arrays and I'm trying to get this program done ASAP the way I know how. I'll definitely look into it once I get a chance to improving my code beyond the "it works" stage.

Solution
‎08-21-2012 07:25 PM
Super User
Super User
Posts: 7,039

Re: SAS Macro in Nested Do Loop "Line generated by the macro variable" error

You appear to have an extra space in the middle of one of statements.

Between the E and A in PRICEAO&i

PROMOPRICEAO&i = PRICE AO&i/ EQREGPRICEAO&i;

New Contributor
Posts: 3

Re: SAS Macro in Nested Do Loop "Line generated by the macro variable" error

Thanks, that was indeed the problem.

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 901 views
  • 0 likes
  • 3 in conversation