BookmarkSubscribeRSS Feed
mohsinm
Calcite | Level 5

Hi all,

 

I have a list of multiple independent variables. I want to run a logistic regression model of each independent variable against an dependent variable and the same process should be repeated for each independent variable against the same target variable and the output statistics should be saved in a dataset.

 

I am using SAS Viya 3.5 version.

 

However, while running the code mentioned in the last, it is showing the following error.

 

ERROR: The %DO statement is not valid in open code.

ERROR: The %end statement is not valid in open code.

 

Is there any other way through which I can get the similar output?

 

Thanks.

 

 

%let dependent_variable = Cholesterol_Status;

%let independent_variables = AgeAtStart Smoking_Status;

 

 

%let variable_list = %scan(&independent_variables, 1);

%let i = 1;

 

%do %while (%length(%scan(&independent_variables, &i)) > 0);

 

 

  %let current_variable = %scan(&independent_variables, &i);

 

 

  proc logistic data=mycaslib.mydata;

    model &dependent_variable = &current_variable;

    score data=mycaslib.mydata out=out_rstore;

  run;

 

 

  %let i = %eval(&i + 1);

 

%end;

 

4 REPLIES 4
Quentin
Super User

As the error says, they %DO statement cannot be used in open code, which means outside of a macro definition.  

 

Typically code like you showed would be inside a macro definition, which starts with a %MACRO statement and ends with a %MEND statement.  Do you see those statements in the code you used as an example to write this code?

The Boston Area SAS Users Group is hosting free webinars!
Next up: Bart Jablonski and I present 53 (+3) ways to do a table lookup on Wednesday Sep 18.
Register now at https://www.basug.org/events.
PaigeMiller
Diamond | Level 26

Macros not needed here, please see this article and in particular the section entitled "The BY way for many models". The article also asserts that this is more efficient than doing this via a macro. (And the programming is already done for you)

--
Paige Miller
mohsinm
Calcite | Level 5

@PaigeMiller  but it is given for linear regression and not for logistic regression. In the comment also complete solution is not given. Thanks.

PaigeMiller
Diamond | Level 26

@mohsinm wrote:

@PaigeMiller  but it is given for linear regression and not for logistic regression.


@mohsinm  Yes, you have to replace the PROC REG code with the desired PROC LOGISTIC code.

 

In the comment also complete solution is not given. 

 

I don't know why you say it is not complete. It looks complete to me. What is missing?

--
Paige Miller

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1006 views
  • 3 likes
  • 3 in conversation