Hi,
I was trying to conduct Cox proportional hazard model using below macro. However, it stopped and gave me error messages " ERROR: More positional parameters found than defined." for the last 6 variables.
%HR(ace_arb);
%HR(ccb);
%HR(asa);
%HR(statin);
%HR(bb);
%HR(Stage);
Below is my SAS macro code:
libname out xlsx "H:\Data\HR_Categorical_RS.xlsx";
%macro HR(x=);
%let outputName=_PE%substr(%cmpres(&x.),1,%sysfunc(min(%length(&x.),29)));
ods graphics off;
ods output ParameterEstimates=&outputName.;
proc phreg data = RS1;
class &x;
model CTOX53cox_interval_1_6_21*CTOX53__within_1_year_of_trastuz(0) = &x /rl;
run;
ods output close;
ods graphics on;
%mend HR;
%HR(x=Age_C);
%HR(x=BMI_C );
%HR(x=Anthracycline__current_or_prior_);
%HR(x=XRT);
%HR(x=ER_cat);
%HR(x=htn);
%HR(x=dm);
%HR(x=hl);
%HR(x=cad);
%HR(x=arrhythmia__AY_adjudicated_1_202);
%HR(x=Smoking);
%HR(x=LVEF_C);
%HR(x=Race);
%HR(x=PR);
%HR(x=Treatment_Year);
%HR(ace_arb);
%HR(ccb);
%HR(asa);
%HR(statin);
%HR(bb);
%HR(Stage);
Below is the log:
2705 %HR(x=Race);
NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: The data set WORK._PERACE has 2 observations and 11 variables.
NOTE: PROCEDURE PHREG used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds
2706 %HR(x=PR);
NOTE: 1 observations were deleted due either to missing or invalid values
for the time, censoring, frequency or explanatory variables or to
invalid operations in generating the values for some of the
explanatory variables.
NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: The data set WORK._PEPR has 1 observations and 11 variables.
NOTE: PROCEDURE PHREG used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
2707 %HR(x=Treatment_Year);
NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: The data set WORK._PETREATMENT_YEAR has 4 observations and 11
variables.
NOTE: PROCEDURE PHREG used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
ERROR: More positional parameters found than defined.
ERROR: More positional parameters found than defined.
2708 %HR(ace_arb);
ERROR: More positional parameters found than defined.
2709 %HR(ccb);
ERROR: More positional parameters found than defined.
2710 %HR(asa);
ERROR: More positional parameters found than defined.
2711 %HR(statin);
ERROR: More positional parameters found than defined.
2712 %HR(bb);
ERROR: More positional parameters found than defined.
2713 %HR(Stage);
Could you please help me with trouble shooting my code? Thank you!
2708 %HR(ace_arb); ERROR: More positional parameters found than defined.
You did not define a positional parameter for macro %HR. And when you call the macro this way, you have a positional paramter ace_arb. The macro %HR as defined only accepts a keyword parameter.
However, this would work
%hr(x=ace_arb)
2708 %HR(ace_arb); ERROR: More positional parameters found than defined.
You did not define a positional parameter for macro %HR. And when you call the macro this way, you have a positional paramter ace_arb. The macro %HR as defined only accepts a keyword parameter.
However, this would work
%hr(x=ace_arb)
When you define a macro with parameters like x= that is a Keyword parameter.
If you do not reference the parameter with the x= in the macro call then SAS treats that as a Positional Parameter(order of appearance assigns value to parameter. All positional parameters must be defined before keyword, if you mix them, so that SAS can tell which goes where. When you define the parameter as a Keyword parameter it is NOT a positional parameter and must be used.
Simple fix: use the X= in the macro calls.
Or if you only have one parameter don't use the keyword definition. Note that for positional parameters x= is still acceptable though arguments may exist about whether it is good style.
One of the reasons for this position first is that keyword parameters may be assigned a default value in the definition. A 'positional' parameter that is attempting to override the defined default doesn't have enough information as to which keyword it might be replacing (remember that some macros can have a LOT of parameters) and the code for the macro processor to "guess" as to the correct usage would be akin to mind reading.
%HR(x=Treatment_Year); %HR(ace_arb);
Looking at your code closely, you can see the macro calls that work are formatted differently from the macro calls that do not, specifically you're missing the X= portion.
@Denali wrote:
Hi,
I was trying to conduct Cox proportional hazard model using below macro. However, it stopped and gave me error messages " ERROR: More positional parameters found than defined." for the last 6 variables.
%HR(ace_arb);
%HR(ccb);
%HR(asa);
%HR(statin);
%HR(bb);
%HR(Stage);
Below is my SAS macro code:
libname out xlsx "H:\Data\HR_Categorical_RS.xlsx";
%macro HR(x=);
%let outputName=_PE%substr(%cmpres(&x.),1,%sysfunc(min(%length(&x.),29)));
ods graphics off;
ods output ParameterEstimates=&outputName.;proc phreg data = RS1;
class &x;
model CTOX53cox_interval_1_6_21*CTOX53__within_1_year_of_trastuz(0) = &x /rl;
run;ods output close;
ods graphics on;%mend HR;
%HR(x=Age_C);
%HR(x=BMI_C );
%HR(x=Anthracycline__current_or_prior_);
%HR(x=XRT);
%HR(x=ER_cat);
%HR(x=htn);
%HR(x=dm);
%HR(x=hl);
%HR(x=cad);
%HR(x=arrhythmia__AY_adjudicated_1_202);
%HR(x=Smoking);
%HR(x=LVEF_C);
%HR(x=Race);
%HR(x=PR);
%HR(x=Treatment_Year);
%HR(ace_arb);
%HR(ccb);
%HR(asa);
%HR(statin);
%HR(bb);
%HR(Stage);
Below is the log:
2705 %HR(x=Race);
NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: The data set WORK._PERACE has 2 observations and 11 variables.
NOTE: PROCEDURE PHREG used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds
2706 %HR(x=PR);NOTE: 1 observations were deleted due either to missing or invalid values
for the time, censoring, frequency or explanatory variables or to
invalid operations in generating the values for some of the
explanatory variables.
NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: The data set WORK._PEPR has 1 observations and 11 variables.
NOTE: PROCEDURE PHREG used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
2707 %HR(x=Treatment_Year);NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: The data set WORK._PETREATMENT_YEAR has 4 observations and 11
variables.
NOTE: PROCEDURE PHREG used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
ERROR: More positional parameters found than defined.
ERROR: More positional parameters found than defined.
2708 %HR(ace_arb);
ERROR: More positional parameters found than defined.
2709 %HR(ccb);
ERROR: More positional parameters found than defined.
2710 %HR(asa);
ERROR: More positional parameters found than defined.
2711 %HR(statin);
ERROR: More positional parameters found than defined.
2712 %HR(bb);
ERROR: More positional parameters found than defined.
2713 %HR(Stage);
Could you please help me with trouble shooting my code? Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: