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?

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: 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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 683 views
  • 3 likes
  • 3 in conversation