Data visualization with SAS programming

Regression

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Regression

I have run a proc reg using the following code and I get an error but I also get the desired plots.    This code was previously used in Base SAS for regression. Can someone tell me why I get this error although the plots are output?

proc reg data=er ALPHA=0.05 OUTSEB COVOUT TABLEOUT OUTEST=outsum ;

57               model change=conc;* / noprint;

58              

61              plots=all;

                 _____

                 180

run;

quit;

NOTE: The previous statement has been deleted.

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

My second question is how do I output the graphs from the plot=all to a folder in the University edition?


Accepted Solutions
Solution
‎08-01-2016 08:17 AM
SAS Super FREQ
Posts: 3,225

Re: Regression

Yes, you can use ODS to do that. We can provide code it you tell us 

1) What graphs you want to output

2) What format you want the graphs to be in (PNG? RTF? PDF?...)

 

Before the call to PROC REG add

ODS TRACE ON;

 

Then when you run the regression the SAS log will give you the names of the ODS graphs that are being produced.

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,225

Re: Regression

[ Edited ]

The PLOTS= option should be placed on the PROC REG statement, like this:

proc reg data=er plots=all ...;

...etc...;

quit;

 

You program generates plots because the REG procedure automatically creates relevant plots when ODS GRAPHICS is turned on (which it is in SAS UE and other SAS interfaces).  Thus you can omit the PLOTS= option if you want to display the default graphs.

 

The ODS statement enables you to open destinations to save the results of an analysis. For example, if you want the tables and graphs saved in a PDF file, use the PDF destination. Want RTF? Use the RTF destination.

 

If you want the graphs saved as PNG files, I think you can use the following statements. This is untested, since I'm not currently at a machine that has SAS UE installed. Write back if it doen't work:
ods html gpath="/folders/myfolders/';   /* folder recognized by SAS UE */

proc reg...;

...etc...;

quit;

 

 

 

Grand Advisor
Posts: 16,315

Re: Regression

You were probably using a different version of SAS - ie 9.3 or 9.2?

 

PLOTS is not a valid statement, as the log indicates, its been removed from the documentation.

http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_reg_syntax01...

 

The PLOTS=(all) statement can go in the PROC REG statement now.

 

proc reg data=sashelp.class plots=(all);
model weight = height age;
run;

I'm not sure what you're looking for as final output, but I would consider creating the file as RTF and then you'll have the output embedded into a Word file.

 

ods rtf file='/folders/myfolders/sample.rtf' style=journal;


*reg code;


ods rtf close;

 

If you really want the graphics as output, you'll need to specify a format type and path. 

 

Contributor
Posts: 46

Re: Regression

The code used was :

ods rtf file='/folders/myfolders/peter_regr/sample.rtf' style=journal;
proc reg data=er plots=(all);
model change=conc;
run;
quit;
ods rtf close;

This code ran okay.  The question that remains is there a way to selectively output only selected graphs  using a different syntax for the plots(all) command?

Solution
‎08-01-2016 08:17 AM
SAS Super FREQ
Posts: 3,225

Re: Regression

Yes, you can use ODS to do that. We can provide code it you tell us 

1) What graphs you want to output

2) What format you want the graphs to be in (PNG? RTF? PDF?...)

 

Before the call to PROC REG add

ODS TRACE ON;

 

Then when you run the regression the SAS log will give you the names of the ODS graphs that are being produced.

Contributor
Posts: 46

Re: Regression

With your  suggested code I did get the names for the outputs.  The only one that I really want is the regression with confidence intervals which is part of the FitPlot.  Unfortunately I get residual plot, and fit diagnostics which I don't want outputted.

Since all of these are part of the FitPlot is there any way to get just the desired plot for the regression?

SAS Super FREQ
Posts: 3,225

Re: Regression

It sounds like you are asking for PLOTS(only)=FitPlot:

 

proc reg data=sashelp.class plots(only)=fitplot;
   model weight=height;
quit;
Contributor
Posts: 46

Re: Regression

Yes, that worked quite well.  One final question if I wanted to use the graph for a presentation is there any way for me to edit the output to remove legends etc if it were output as a word document instead of an rtf file?

SAS Super FREQ
Posts: 3,225

Re: Regression

You can remove the statistics by using 

plots(only)=fitplot(stats=none);

 

The PROC REG doc also shows that you can remove the prediction limits (NOCLI) and the confidence band (NOCLM).

 

For more elaborate customization, I suggest learning to use the SGPLOT procedure. The REG statement in PROC SGPLOT  performs simple regression and enables complete control over all attributes.

Contributor
Posts: 46

Re: Regression

I will use SGplot which will give me more control similar to when one uses gplot in base SAS.

Thanks for the help.

Contributor
Posts: 46

Re: Regression

I am running the following code as previously discussed:

 

ods rtf file='/folders/myfolders/peter/sample1.rtf' style=journal;

ods trace on;

proc reg data=boot plots=all;

model Clu=GFru;

run;

quit;

ods rtf close;

 

It ran okay and I got all of the plots and the analysis of variance results.  My question is how does one get the observed and predicted values (slope, intercept etc) output as well as their 90% confidence intervals in a table?

 

Super Contributor
Posts: 252

Re: Regression

Does including the following statement help?

 

output out = predicted p=p lcl =lcl lclm =lclm ucl =ucl uclm =uclm;

Contributor
Posts: 46

Re: Regression

I put it in but got no output although it works with base SAS but I guess it may not be the proper syntax for University SAS.  I have trace on for my ODS and there is an output  called FitStatistics which I have tried to add to the code as:

proc reg data =boot1 plots=all Fit Statistics;

 

However I get a syntax error.  Can someone tell me how to correct the statement to get the output of Fit Statistics and the plots?

Super Contributor
Posts: 252

Re: Regression

Oh okay, maybe the syntax is different for SAS University then.


Anyway when you use ODS trace to find table names, to output them you need to add ods output too. i.e.:

 

ods output Fit Statistics = Fit Statistics;

 

Put the above statement just before your proc reg.

Super Contributor
Posts: 252

Re: Regression

Also Fit Statistics should be one word....

Post a Question
Discussion Stats
  • 17 replies
  • 446 views
  • 0 likes
  • 4 in conversation