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

Hi Everyone,

 

I am trying to follow similar coding to the UCLA help guide here: 

https://stats.idre.ucla.edu/sas/code/ummary-table-for-multiple-regression-models/

 

I only have three differences:

1) I need three decimal places - I think I solved that one

2) I need to label my variables using different names - how do I change it in the proc tabulate statement? - (For example, from math to "Mathematics"?

3) Rather than using proc reg, I need to use proc surveyreg statement - see the following code I use and the log that I get:

 

proc format;
picture estimate (round)
low-high=' 9.999'
.=' '; picture stderrf (round) low-high=' 9.99)' (prefix='(') .=' '; run;

ods output ParameterEstimates (persist) = t;                        
                                                                    
proc surveyreg data = "d:datahsb2" ;   
cluster school;
class year incomerange; model write = female / noint ADJRSQ solution; model write = female read / noint ADJRSQ solution;
WARNING: Multiple MODEL statements. Only the first MODEL statement will be used.
model write = female read math / noint ADJRSQ solution;
WARNING: Multiple MODEL statements. Only the first MODEL statement will be used.
run; ods output close; proc print data=t; run;

proc tabulate data=t noseps;      
  class model variable;  
ERROR: Variable MODEL not found.
ERROR: Variable VARIABLE not found.
var estimate stderr; table variable=''*(estimate =' '*sum=' '*F=estimate. stderr=' '*sum=' '*F=stderrf.), model=' ' / box=[label="Parameter"] rts=15 row=float misstext=' '; run;
 
 

 How would I fix the error on the log that I get?

 

If I can't use proc tabulate with proc surveyreg, what kind of code would I use?

 

Please somebody help me!

 

Thanks,

the rock

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@therock wrote:

Hi Everyone,

 

I am trying to follow similar coding to the UCLA help guide here: 

https://stats.idre.ucla.edu/sas/code/ummary-table-for-multiple-regression-models/

 

I only have three differences:

1) I need three decimal places - I think I solved that one

2) I need to label my variables using different names - how do I change it in the proc tabulate statement? - (For example, from math to "Mathematics"?

3) Rather than using proc reg, I need to use proc surveyreg statement - see the following code I use and the log that I get:

 

proc format;
picture estimate (round)
low-high=' 9.999'
.=' '; picture stderrf (round) low-high=' 9.99)' (prefix='(') .=' '; run;

ods output ParameterEstimates (persist) = t;                        
                                                                    
proc surveyreg data = "d:datahsb2" ;   
cluster school;
class year incomerange; model write = female / noint ADJRSQ solution; model write = female read / noint ADJRSQ solution;
WARNING: Multiple MODEL statements. Only the first MODEL statement will be used.
model write = female read math / noint ADJRSQ solution;
WARNING: Multiple MODEL statements. Only the first MODEL statement will be used.
run; ods output close; proc print data=t; run;

proc tabulate data=t noseps;      
  class model variable;  
ERROR: Variable MODEL not found.
ERROR: Variable VARIABLE not found.
var estimate stderr; table variable=''*(estimate =' '*sum=' '*F=estimate. stderr=' '*sum=' '*F=stderrf.), model=' ' / box=[label="Parameter"] rts=15 row=float misstext=' '; run;
 
 

 How would I fix the error on the log that I get?

 

If I can't use proc tabulate with proc surveyreg, what kind of code would I use?

 

Please somebody help me!

 

Thanks,

the rock


It looks like @Reeza is addressing the Surveyreg parts, so I'll not add confusion with comments on that.

In Proc tabulate if you want to change the label for a variable everywhere it appears it you can use a LABEL statement just as you would in a data step, proc print or other procedure. If you are generating multiple tables in a single Proc Tabulate call you can override or provide a different label in the TABLE statement by adding ='something' after the variable or requested statistic.

Example below shows one tabulate call with different labels for the SEX variable from the SASHELP.CLASS data set you should have available.

proc tabulate data=sashelp.class;
   class sex age;
   var height weight;
   label sex='Student Gender';
   table sex,
         height*(max min)
   ;
   table age*sex='Gender',
         height*max;
run;

As far as providing apparently 3 values in a single cell as implied by your desired output

 

2.6705
(0.5842)***

 

Tabulate allows a single value in a single report "cell" and has to be the result of a single statistic. You can play some games with making cell values appear somewhat like that in a printed output by making the cell borders apparently disappear but there still needs to be three separate statistics based on your variables. If you really want three values in a single cell with that appearance you will likely have to build the values in a data step and possibly get output with either proc print or the Report Writing Interface.

 

The contents of the data set determine what you can do with any of the report procedures, not which procedure generates them. Often your output from procedure may need addition variable(s), transposition or even sorting to get desired appearances.

View solution in original post

8 REPLIES 8
Reeza
Super User
Can you add some comments to what you think each step is doing and then post what you want to do?

Also, did you run the demo code exactly and make sure it actually works?
therock
Calcite | Level 5

Hi Reeza,

 

So for your second question, the demo code works as it is supposed to work. I did not have to make any changes.

 

For your first question, proc format step works okay. The proc surveyreg step does not work as the "persist" comment on the ods step will not work with the surveyreg step. I have included the log in the code. For the proc tabulate statement, I have included the log in the code. It cannot find the "model" and "variable."

 

What I want is to run the demo code but use the proc surveyreg (rather than the proc reg used in the demo) in the order to get the final output to look like this (where statistical significance at 10%, 5%, and 1% is denoted by *, **, and ***, respectively.):

 

 VariableWriteWriteWrite
Female2.6705
(0.5842)***
0.1180
(0.0275)***
0.0043
(0.0157)
Math -0.0342
(0.0147)**
-0.1115
(0.0126)***
Read  0.0035
(0.0204)


   
Number of Schools178317911778
R20.51990.49880.0103

 

If you know a better way to get the final output to look like this, I would appreciate it.

 

Thanks,

the rock

Reeza
Super User

You did not attach any code or log.

 

To get your PROC SURVEYREG working, make sure to replace the DATA=reference to an actual data set. Although it's possible to include a path reference to a SAS data set and use that, I would highly recommend against that method. It's both unconventional and a pain to maintain. 

 

Instead, write a libname reference and use the file from there with the data set name. 

 

The UCLA SurveyReg has a better example:

https://stats.idre.ucla.edu/sas/code/proc-surveyreg-examples/

 

Then your ODS statement will work. It's not working now because the SURVEYREG code is incorrect, or at least that's my assumption since mine works fine.  The PERSIST option is when you're running multiple surveyregs back to back and want to store them all in one table, which it doesn't appear you're doing. 

 

And the TABULATE the code won't work exactly as specified because you're using a different PROC. The PROC TABULATE will not work but the estimates are created. What you need to do is run the demo, and map the column/variable names to the TABULATE code. Then look at the output from SurveyReg in the parameter estimates table and determine which variable maps to which and change the references. 

 


@therock wrote:

Hi Reeza,

 

So for your second question, the demo code works as it is supposed to work. I did not have to make any changes.

 

For your first question, proc format step works okay. The proc surveyreg step does not work as the "persist" comment on the ods step will not work with the surveyreg step. I have included the log in the code. For the proc tabulate statement, I have included the log in the code. It cannot find the "model" and "variable."

 

What I want is to run the demo code but use the proc surveyreg (rather than the proc reg used in the demo) in the order to get the final output to look like this (where statistical significance at 10%, 5%, and 1% is denoted by *, **, and ***, respectively.):

 

 Variable Write Write Write
Female 2.6705
(0.5842)***
0.1180
(0.0275)***
0.0043
(0.0157)
Math   -0.0342
(0.0147)**
-0.1115
(0.0126)***
Read     0.0035
(0.0204)


     
Number of Schools 1783 1791 1778
R2 0.5199 0.4988 0.0103

 

If you know a better way to get the final output to look like this, I would appreciate it.

 

Thanks,

the rock


 

 

ballardw
Super User

@therock wrote:

Hi Everyone,

 

I am trying to follow similar coding to the UCLA help guide here: 

https://stats.idre.ucla.edu/sas/code/ummary-table-for-multiple-regression-models/

 

I only have three differences:

1) I need three decimal places - I think I solved that one

2) I need to label my variables using different names - how do I change it in the proc tabulate statement? - (For example, from math to "Mathematics"?

3) Rather than using proc reg, I need to use proc surveyreg statement - see the following code I use and the log that I get:

 

proc format;
picture estimate (round)
low-high=' 9.999'
.=' '; picture stderrf (round) low-high=' 9.99)' (prefix='(') .=' '; run;

ods output ParameterEstimates (persist) = t;                        
                                                                    
proc surveyreg data = "d:datahsb2" ;   
cluster school;
class year incomerange; model write = female / noint ADJRSQ solution; model write = female read / noint ADJRSQ solution;
WARNING: Multiple MODEL statements. Only the first MODEL statement will be used.
model write = female read math / noint ADJRSQ solution;
WARNING: Multiple MODEL statements. Only the first MODEL statement will be used.
run; ods output close; proc print data=t; run;

proc tabulate data=t noseps;      
  class model variable;  
ERROR: Variable MODEL not found.
ERROR: Variable VARIABLE not found.
var estimate stderr; table variable=''*(estimate =' '*sum=' '*F=estimate. stderr=' '*sum=' '*F=stderrf.), model=' ' / box=[label="Parameter"] rts=15 row=float misstext=' '; run;
 
 

 How would I fix the error on the log that I get?

 

If I can't use proc tabulate with proc surveyreg, what kind of code would I use?

 

Please somebody help me!

 

Thanks,

the rock


It looks like @Reeza is addressing the Surveyreg parts, so I'll not add confusion with comments on that.

In Proc tabulate if you want to change the label for a variable everywhere it appears it you can use a LABEL statement just as you would in a data step, proc print or other procedure. If you are generating multiple tables in a single Proc Tabulate call you can override or provide a different label in the TABLE statement by adding ='something' after the variable or requested statistic.

Example below shows one tabulate call with different labels for the SEX variable from the SASHELP.CLASS data set you should have available.

proc tabulate data=sashelp.class;
   class sex age;
   var height weight;
   label sex='Student Gender';
   table sex,
         height*(max min)
   ;
   table age*sex='Gender',
         height*max;
run;

As far as providing apparently 3 values in a single cell as implied by your desired output

 

2.6705
(0.5842)***

 

Tabulate allows a single value in a single report "cell" and has to be the result of a single statistic. You can play some games with making cell values appear somewhat like that in a printed output by making the cell borders apparently disappear but there still needs to be three separate statistics based on your variables. If you really want three values in a single cell with that appearance you will likely have to build the values in a data step and possibly get output with either proc print or the Report Writing Interface.

 

The contents of the data set determine what you can do with any of the report procedures, not which procedure generates them. Often your output from procedure may need addition variable(s), transposition or even sorting to get desired appearances.

therock
Calcite | Level 5

Hi Reeza and Ballardw,

 

I apologize for the confusion I created. Let me start at the beginning. Suppose I have a database with the following variables:

Sex: Dummy Variable

Write: Continuous Variable

Math: Continuous Variable

Read: Continuous Variable

Science: Continuous Variable

Income: Dummy Variable (Above/Below Middle Class)

Age: Continuous Variable

Siblings: Category

Year: Continuous Variable

ID: Student ID

 

Here is the equations and SAS code that I have so far:

 

proc surveyreg data=example;

cluster id;

class year siblings;

model write = sex income sex*income math science / noint adjsq solution;

run;

 

proc surveyreg data=example;

cluster id;

class year siblings;

model read = sex income sex*income math science / noint adjsq solution;

run;

 

When I ran the two models on SAS, I get the correct estimate. My problem is that I do not want in that format. Here is the format that I want: 

 

image.png

Reeza
Super User
You can combine the output manually and use PROC REPORT for the display portion. There isn’t a standard output because everyone wants something slightly different.
therock
Calcite | Level 5

I have to break the post in two part. Sorry about that. 

 

Going back to the previous post, I thought that the UCLA would be helpful but the modified code did not work. My request can someone help me with a code to put the proc surveyreg results into the format that I want?

ballardw
Super User

@therock wrote:

I have to break the post in two part. Sorry about that. 

 

Going back to the previous post, I thought that the UCLA would be helpful but the modified code did not work. My request can someone help me with a code to put the proc surveyreg results into the format that I want?


Have you determined which data you want (table name) and how to direct that to an output data set? That would be the first step.

For example if you want the parameter estimates which would be in the ParameterEstimates table you would use something like

proc surveyreg data=example;
   cluster id;
   class year siblings;
   model write = sex income sex*income math science / noint adjsq solution;
   ods output ParameterEstimates = work.myparameters;
run;

Each table of output has a different name. You see which ones are generated by your procedure using ODS TRACE=ON; before running the procedure or check in the details of the procedure documentation for table names generated by which statement.

 

With a data set you can then manipulate it with either data step code or a reporting procedure, possibly combining multiple output sets.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1689 views
  • 0 likes
  • 3 in conversation