DATA Step, Macro, Functions and more

SAS MAcro for logistic regression model

Not applicable
Posts: 0

SAS MAcro for logistic regression model

Hi, I am not sure how to write macro for a LR program where
proc logistic descending;
model y=x a b c d ..; run;

yet I need many iterative steps for the variable x that starts with 'rs' and then the number.

can u please help? !!

Thanks much
Valued Guide
Posts: 653

Re: SAS MAcro for logistic regression model

Posted in reply to deleted_user
I think you are asking to insert a series of model statements into your PROC LOGISTIC step. The following untested macro allows you to build as many MODEL statements as you need (the default is 10 and the macro call requests 25).

[pre]%macro logistic(models=10);
%local i;
proc logistic data=mydata descending;
%do i = 1 %to ⊧
rs&i: model y = rs&i a b c d;
%mend logistic;
Respected Advisor
Posts: 3,852

Re: SAS MAcro for logistic regression model

I think your macro probably works but PROC LOGISTIC does not allow multiple model statements like PROC REG. V 9.1.3 anyway.

421 proc logistic data=sashelp.class descending;
422 weight: model sex = weight;
423 height: model sex = height;
424 run;

ERROR: Only one MODEL statement can be used with each invocation of PROC LOGISTIC.

I find that for a situation that the OP describes it is more satisfying to fiddle with the data and use a BY statement than to fiddle with macros.

data class;
set sashelp.class;
array rs[10];
do _n_ = 1 to dim(rs);
rs[_n_] = ranuni(123);
proc transpose data=class out=tclass;
by name sex age weight height;
var rs:;
data tclass;
set tclass;
order = input(substr(_name_,3),8.);
proc sort data=tclass;
by order;
proc logistic data=tclass;
by _name_ notsorted;
model sex = col1 age weight height;

You don't have to create the ORDER variable but without it RS1 is followed by RS10 and you probably prefer RS2 to follow RS1.
Not applicable
Posts: 0

Re: Ods output in a Macro program - please help

Posted in reply to deleted_user
I guess I have a trouble with Ods Ouput now, the macro for LR works.

I used the similar ods output to collect pvalues in the PHREG statement and it was totally fine, but now I am given the error message that the variable 'Parameter' has never been referenced. Also I am getting this WARNING: Duplicate data set name on ODS OUTPUT statement. Entry will be ignored.

here is my program:

%MACRO logistic;
%local I;

%DO I=1 %TO x;

ods output ParameterEstimates=Results;

DATA a; SET b; df=d*f; RUN;

proc logistic descending data=a;

MODEL y=d f df e.. ;

ods OUTPUT close;

DATA Estimate; SET Results; WHERE Parameter="df"; KEEP Parameter
ProbChiSq ; RUN;

%MEND logistic;
Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation