BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dbcrow
Obsidian | Level 7

Hi, folks: 

 

I'm having the devil of a time trying to do something that should be easy:  save the random effects BLUPs into a data set.  (I have SAS Enterprise Guide 7.1 and SAS 9.4.) 

 

The dataset consists of around 20k respondents nested in 58 counties.  There are just two variables:  a county indicator and a dummy variable indicating whether the respondent is employed or not. 

 

The model is the simplest possible:  a random intercepts model to get county-level unemployment estimates: 

 

/*Random Intercepts*/
proc glimmix data=opioid_cty2 itdetails method=quad(qpoints=10);
	class county;
	model unemp(event="1") = / solution link=logit dist=binary oddsratio;
	random intercept / subject=county solution;
run;

 

Here are some lines from the output for the solved random effects: 

 

Picture1.png

 

Here are my questions: 

 

1)  How can I save this table as a data set quickly and easily?  Is there some output option in the "RANDOM" statement?  Or do I have to use the "OUTPUT" statement, "PRED" option, to get the BLUPs and then post-process the heck out of the data with, say, PROC MEANS?  (Note that I can't use "LSMEANS", since the level-two, subject variable, county, is not in the model statement.) 

 

2)  How can I get the estimates on the scale of the original data--i.e., get estimated probabilities--in this solution table?  Or is that something I would have to do in the "OUTPUT" statement? 

 

3)  Why is the "oddsratio" option in the "MODEL" statement not giving me odds ratios?  Obviously, I could get the odds ratios (and probabilities) by simply applying the antilog to these estimates.  I'm just vexed by my inability to get the "oddsratio" option to work. 

 

Thanks!  🙂 

David

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

1) If it's output you can see, you can use ODS to capture it. Here's a blog post on how it works and where to find the correct table names. 

https://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

 

2) For estimates for data modeled you can use OUTPUT out= data statement, with the Predicted option specified.

output out = predictions pred=p resid=r;

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_glimmix_syntax19.htm&docsetVersio...

 

3) Not sure, what does the log say? It will usually indicate why an option didn't work. 

 


@dbcrow wrote:

Hi, folks: 

 

I'm having the devil of a time trying to do something that should be easy:  save the random effects BLUPs into a data set.  (I have SAS Enterprise Guide 7.1 and SAS 9.4.) 

 

The dataset consists of around 20k respondents nested in 58 counties.  There are just two variables:  a county indicator and a dummy variable indicating whether the respondent is employed or not. 

 

The model is the simplest possible:  a random intercepts model to get county-level unemployment estimates: 

 

/*Random Intercepts*/
proc glimmix data=opioid_cty2 itdetails method=quad(qpoints=10);
	class county;
	model unemp(event="1") = / solution link=logit dist=binary oddsratio;
	random intercept / subject=county solution;
run;

 

Here are some lines from the output for the solved random effects: 

 

Picture1.png

 

Here are my questions: 

 

1)  How can I save this table as a data set quickly and easily?  Is there some output option in the "RANDOM" statement?  Or do I have to use the "OUTPUT" statement, "PRED" option, to get the BLUPs and then post-process the heck out of the data with, say, PROC MEANS?  (Note that I can't use "LSMEANS", since the level-two, subject variable, county, is not in the model statement.) 

 

2)  How can I get the estimates on the scale of the original data--i.e., get estimated probabilities--in this solution table?  Or is that something I would have to do in the "OUTPUT" statement? 

 

3)  Why is the "oddsratio" option in the "MODEL" statement not giving me odds ratios?  Obviously, I could get the odds ratios (and probabilities) by simply applying the antilog to these estimates.  I'm just vexed by my inability to get the "oddsratio" option to work. 

 

Thanks!  🙂 

David

 

 

 

 


 

View solution in original post

3 REPLIES 3
Reeza
Super User

1) If it's output you can see, you can use ODS to capture it. Here's a blog post on how it works and where to find the correct table names. 

https://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

 

2) For estimates for data modeled you can use OUTPUT out= data statement, with the Predicted option specified.

output out = predictions pred=p resid=r;

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_glimmix_syntax19.htm&docsetVersio...

 

3) Not sure, what does the log say? It will usually indicate why an option didn't work. 

 


@dbcrow wrote:

Hi, folks: 

 

I'm having the devil of a time trying to do something that should be easy:  save the random effects BLUPs into a data set.  (I have SAS Enterprise Guide 7.1 and SAS 9.4.) 

 

The dataset consists of around 20k respondents nested in 58 counties.  There are just two variables:  a county indicator and a dummy variable indicating whether the respondent is employed or not. 

 

The model is the simplest possible:  a random intercepts model to get county-level unemployment estimates: 

 

/*Random Intercepts*/
proc glimmix data=opioid_cty2 itdetails method=quad(qpoints=10);
	class county;
	model unemp(event="1") = / solution link=logit dist=binary oddsratio;
	random intercept / subject=county solution;
run;

 

Here are some lines from the output for the solved random effects: 

 

Picture1.png

 

Here are my questions: 

 

1)  How can I save this table as a data set quickly and easily?  Is there some output option in the "RANDOM" statement?  Or do I have to use the "OUTPUT" statement, "PRED" option, to get the BLUPs and then post-process the heck out of the data with, say, PROC MEANS?  (Note that I can't use "LSMEANS", since the level-two, subject variable, county, is not in the model statement.) 

 

2)  How can I get the estimates on the scale of the original data--i.e., get estimated probabilities--in this solution table?  Or is that something I would have to do in the "OUTPUT" statement? 

 

3)  Why is the "oddsratio" option in the "MODEL" statement not giving me odds ratios?  Obviously, I could get the odds ratios (and probabilities) by simply applying the antilog to these estimates.  I'm just vexed by my inability to get the "oddsratio" option to work. 

 

Thanks!  🙂 

David

 

 

 

 


 

dbcrow
Obsidian | Level 7

Reezas-

 

As ever, thanks.  

 

Clearly, I need to master the ODS system.  Regarding (2), getting the solution output in estimated probabilities, I'm afraid that perhaps I wasn't clear enough.  I don't want estimated probabilities at the individual level (Level 1), but rather at the county level (Level 2).  It looks like the output statement gives the former, but not the latter.  What I would like is for the ODS table of solved random effects (BLUPs) to be reported not as logged odds, but rather as probabilities.  Can this be done?  

 

W.r.t. (3), the "oddsratio" option (apparently) not working, here's the complete output log:  

 

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='opioid_analysis';
4          %LET _CLIENTPROJECTPATH='C:\Users\DCrow\Documents\CHIS\Opioid\opioid_cty.egp';
5          %LET _CLIENTPROJECTNAME='opioid_cty.egp';
6          %LET _SASPROGRAMFILE='C:\Users\DCrow\Documents\CHIS\Opioid\opioid_analysis.sas';
7          
8          ODS _ALL_ CLOSE;
9          OPTIONS DEV=ACTIVEX;
10         GOPTIONS XPIXELS=0 YPIXELS=0;
11         FILENAME EGSR TEMP;
12         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
13             STYLE=HtmlBlue
14             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
15             NOGTITLE
16             NOGFOOTNOTE
17             GPATH=&sasworklocation
18             ENCODING=UTF8
19             options(rolap="on")
20         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
21         
22         GOPTIONS ACCESSIBLE;
23         
24         /*Random Intercepts*/
25         proc glimmix data=opioid_cty2 itdetails method=quad(qpoints=10);
26         	class county;
27         	model unemp(event="1") = / solution link=logit dist=binary oddsratio;
28         	random intercept / subject=county solution;
29         run;




NOTE: Some observations are not used in the analysis because of: missing subject effects (n=639).
NOTE: The GLIMMIX procedure is modeling the probability that unemp='1'.
NOTE: Convergence criterion (GCONV=1E-8) satisfied.
NOTE: At least one element of the gradient is greater than 1e-3.
NOTE: PROCEDURE GLIMMIX used (Total process time):
      real time           5.98 seconds
      cpu time            5.78 seconds
      

30         
31         
32         
33         GOPTIONS NOACCESSIBLE;
34         %LET _CLIENTTASKLABEL=;
35         %LET _CLIENTPROJECTPATH=;
36         %LET _CLIENTPROJECTNAME=;
37         %LET _SASPROGRAMFILE=;
38         
39         ;*';*";*/;quit;run;
40         ODS _ALL_ CLOSE;
41         
42         
43         QUIT; RUN;
44         

I'm not seeing anything there that would indicate why the "oddsratio" option isn't giving me the solution output in odds ratios (instead of the logged odds ratio it's giving me now).  

 

Does this make sense?  

 

Regards,

David

Reeza
Super User

For #2 then you either want to add the BLUP option OR you may want the LSMEANS (or ESTIMATE or CONTRAST) statements to get your estimates. 

 

For #3 - ODDS ratio appears to want a variable in the model, which you don't really have here. 

 

requests estimates of odds ratios and their confidence limits, provided the link function is the logit, cumulative logit, or generalized logit. Odds ratios are produced for the following:

  • classification main effects, if they appear in the MODEL statement

  • continuous variables in the MODEL statement, unless they appear in an interaction with a classification effect

  • continuous variables in the MODEL statement at fixed levels of a classification effect, if the MODEL statement contains an interaction of the two

  • continuous variables in the MODEL statement, if they interact with other continuous variables

I don't think your model meets any of these?

 

Probably as much as I can answer with my limited knowledge of GLIMMIX. If you still have questions, one of the others will have to chime in 🙂

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 3408 views
  • 1 like
  • 2 in conversation