DATA Step, Macro, Functions and more

SAS MAcro for logistic regression model

Reply
N/A
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: 634

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;
%end;
run;
%mend logistic;
%logistic(models=25)
[/pre]
Respected Advisor
Posts: 3,799

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.

[pre]
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.
[/pre]

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.

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

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.
N/A
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.. ;
RUN;

ods OUTPUT close;

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

DATA PVALUE; SET PVALUE Estimate; RUN;
%END;
%MEND logistic;
%logistic;
Ask a Question
Discussion stats
  • 3 replies
  • 801 views
  • 0 likes
  • 3 in conversation