BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
ArtC
Rhodochrosite | Level 12
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]
data_null__
Jade | Level 19
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.
deleted_user
Not applicable
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2736 views
  • 0 likes
  • 3 in conversation