BookmarkSubscribeRSS Feed
cindyf
Calcite | Level 5

Hi all, 

I need to run hundreds of univariate logistic regression models with p values for each model.  This macro is able to generate actual beta, but I can't seem to get p values. I tried to insert ODS OUTPUT ParameterEstimates=_parm;before logistic statement but the _parm dataset is no generated. Can anyone please help me? thanks!

 

%let nCont = 100;    
%macro RunReg(DSName, NumVars);
options nonotes;  
proc datasets nolist; 
  delete AllStats;  
run;
 
%do i = 1 %to &NumVars;   
 
proc logistic data=&DSName noprint
            outest=PE(rename=(read&i=Value));
model rec = read&i;      
  
run;
   proc append base=AllStats data=pe; run;
%end;
 
options notes;
%mend;
%RunReg(sas1, &nCont)
3 REPLIES 3
PaigeMiller
Diamond | Level 26

@cindyf wrote:

I tried to insert ODS OUTPUT ParameterEstimates=_parm;before logistic statement but the _parm dataset is no generated. Can anyone please help me? thanks!

 

%let nCont = 100;    
%macro RunReg(DSName, NumVars);
options nonotes;  
proc datasets nolist; 
  delete AllStats;  
run;
 
%do i = 1 %to &NumVars;   
 
proc logistic data=&DSName noprint
            outest=PE(rename=(read&i=Value));
model rec = read&i;      
  
run;
   proc append base=AllStats data=pe; run;
%end;
 
options notes;
%mend;
%RunReg(sas1, &nCont)

Please do this. First, run the command options mprint; Then, set &nCont=1 (for debugging purposes), add in the ODS OUTPUT statement to the above code, and run the macro again, and then show us the log. We need to see the entire log for this run of the macro, every single line, every single character, with nothing removed. Please format the log properly by copying it as text, and pasting it into the window that appears when you click on the </> icon (see below).

 

Insert Log Icon in SAS Communities.png

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hi @cindyf and welcome to the SAS Support Communities!

 

The ODS OUTPUT statement doesn't create the _parm dataset because of the NOPRINT option of the PROC LOGISTIC statement. So omit the NOPRINT option and use ODS SELECT NONE instead to suppress the printed output. With the PERSIST=PROC option of the ODS OUTPUT statement you can tell SAS to add new observations to dataset _parm in each iteration of your macro loop. You should also close the PROC DATASETS step with a QUIT statement before subsequent ODS statements. Here's a modified version of your code including these suggestions (highlighted in blue):

%let nCont = 100;
%macro RunReg(DSName, NumVars);
options nonotes;
proc datasets nolist;
  delete AllStats;
quit;

ods select none;
ods output ParameterEstimates(persist=proc)=_parm;
%do i = 1 %to &NumVars;

  proc logistic data=&DSName /* noprint */
              outest=PE(rename=(read&i=Value));
  model rec = read&i;
  run;

  proc append base=AllStats data=pe;
  run;

%end;
ods select all;
options notes;
%mend RunReg;
%RunReg(sas1, &nCont)

Having most of the statistics in dataset _parm, you maybe don't need the AllStats dataset anymore, so you could simplify the code considerably.

PaigeMiller
Diamond | Level 26

Great job, @FreelanceReinh , you have clearly identified the problem and its solution.

 

@cindyf I'd like to offer some advice that I think will help you with similar issues in the future, that will lead to a faster resolution of the problem, or avoiding the problem altogether.

 

You should always be reading the log (see Maxim 2). When your code isn't working, you should always be showing us the log for the relevant parts of the code, with nothing chopped out.

 

Here's what the log says is a similar case (emphasis mine)

 

WARNING: Output 'parameterestimates' was not created. Make sure that the output object name, label, or path is spelled correctly. Also, verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used.
 

 

I also advise an approach to writing macros, a highly recommended approach, in which you first create working valid SAS code without macros, for one or two iterations. Once you have working valid SAS code without macros, then you can turn it into a working macro much more easily. Had you done this, you would have gotten the proper output with your non-macro code, and then no problems in turning it into a macro.

 

 

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 626 views
  • 1 like
  • 3 in conversation