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 = ¤t_variable;
score data=mycaslib.mydata out=out_rstore;
run;
%let i = %eval(&i + 1);
%end;
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?
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)
@PaigeMiller but it is given for linear regression and not for logistic regression. In the comment also complete solution is not given. Thanks.
@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?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.