BookmarkSubscribeRSS Feed
Joseph0828
Calcite | Level 5

I am currently building a multiple logistic regression, Before that, I will do univariate analysis for each variable including both categorical and continuous data (around 20~). I am doing a macro to help it more efficient. This is the code i am using now but this does not work and SAS log said : Libref E is not assigned. I wonder how i should adjust the code. Thank you!
.

 

%let var = BMI air1 years etc. ;
%macro univar;
%do i=1 %to %eval(%sysfunc(countc(&var., " BMI air1 years etc."))+1);
%let var1 = %scan(&var, &i);
%put var1;
proc logistic descending data = e;
model cvs1 = &var1.;
run;
%end;
%mend;

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

First step to getting a macro to work ... create code without macros and without macro variables that works properly for one hard-coded instance of your problem. You haven't done this. If your code won't work without macros and without macro variables, then it most certainly will never work with macro variables and with macros.

 

So, show me code that works without macros and without macro variables for one hard-coded instance of your problem.

 

Furthermore, never show us a small portion of the messages in the log. Never show us errors in the macro out of context, we need to see the code that generated the error as it appears in the log. Show us the entire log for this macro (or if it is a large log, show us the 50 lines or so before the error).

 

The above text is put forth for your future benefit whenever you decide to write a macro. There is no need to write macros for this problem, and the non-macro version will most likely be more efficient than the macro version. Please see: https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html

--
Paige Miller
Tom
Super User Tom
Super User

To count the number of words in a list use the COUNTW() function, not the COUNT() function.

Remember to tell both %SCAN() and COUNTW() what delimiter you are using between the words in the list.

%do i=1 %to %sysfunc(countw(&var,%str( )));
  %let var1 = %scan(&var, &i,%str( ));
Reeza
Super User

This page has the exact example you're trying to build about half way down the page.

https://stats.oarc.ucla.edu/sas/seminars/sas-macros-introduction/

 

 

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 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
  • 913 views
  • 0 likes
  • 4 in conversation