BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

22 REPLIES 22
Rick_SAS
SAS Super FREQ

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;

 

 

 

Reeza
Super User

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. 

 

jacksonan123
Lapis Lazuli | Level 10

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?

Rick_SAS
SAS Super FREQ

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.

jacksonan123
Lapis Lazuli | Level 10

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?

Rick_SAS
SAS Super FREQ

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

 

proc reg data=sashelp.class plots(only)=fitplot;
   model weight=height;
quit;
jacksonan123
Lapis Lazuli | Level 10

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?

Rick_SAS
SAS Super FREQ

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.

jacksonan123
Lapis Lazuli | Level 10

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

Thanks for the help.

acordes
Rhodochrosite | Level 12

Dear Rick,

I would like to fuse this selective output facility with your trick about animated output

https://blogs.sas.com/content/iml/2016/08/22/animation-by-statement-proc-sgplot.html

 

so that I can show how the regression behaves over time.

I am nearly done but I need to suppress the tables output which precedes the fitplot.

How can I do this?

I could do a workaround saving the parameterestimates, scoring the data set and plotting the results but I am looking for the most direct solution.

Thanks, Arne

 

Rick_SAS
SAS Super FREQ

Use ODS EXCLUDE to name any tables that you want to exclude.  Alternatively, you can use

ODS EXCLUDE ALL;

ODS SELECT <name of tables/graphs you want>;

 

For a longer discussion about how to exclude output in SAS, see "What is the best way to suppress ODS output in SAS?"  If you don't know the name of the table, use ODS TRACE ON to find the name of the ODS object.

acordes
Rhodochrosite | Level 12

It works 🙂

In my case I have to exclude

 

ODS EXCLUDE ParameterEstimates FitStatistics ANOVA NObs;;

 

One last question regarding this topic: Can I force proc reg to use the same axis values range when using the BY statement?

I suppose that I can´t. 

No problem, I´ll fix it with proc reg OUTEST option, then proc score and then sgplot.

acordes
Rhodochrosite | Level 12

@Rick_SAS 

 

I have used a trick to unify the xaxis and yaxis range of the proc reg fitplot output.

Knowing the extreme values of the variables related to both axis (independent and dependent variables in the context of a regression) I add these dummy values to the data set so that each by group has the same upper and lower bound corresponding to the upper left and lower right area of the plot.

In order to avoid that these dummy values affect my regression, I create another dummy variable weight which gets assigned 1 for real observations and near 0 for the dummy values. 

Then I run the regression on this extended data set including a weight statement.

As a result all fitplots share the same axis ranges and used in the context of the animated gif the transition looks smooth.

 

If I don't suppress the by title display (NOBYLINE), I end up having a strange first frame without the correct by title. 

 

Here comes the code:

 

 

ods graphics / imagefmt=GIF width=8in height=6in  ;     /* each image is 4in x 3in GIF */
options papersize=('8 in', '6 in')                    /* set size for images */
        nodate nonumber   
		/* do not show date, time, or frame number */
        animduration=0.2 animloop=yes NOANIMOVERLAY NOBYLINE     /* animation details */
        printerpath=gif animation=start;              /* start recording images to GIF */
ods printer file='C:\Users\DKXENLO\Desktop\OUTOUT\Anim3.gif' NOGTITLE DPI=300;  /* images saved into animated GIF */
 
ods html select none;                                 /* suppress screen output */

ODS EXCLUDE ParameterEstimates FitStatistics ANOVA NObs;
PROC REG DATA=WORK.ALL PLOTS(ONLY)=FITPLOT(nocli NOCLM STATS=NONE) outest=oest   ;
WEIGHT WT;
BY ASSESS_D;
MODEL SALES_RES = MESES_EFECTIVOS;
RUN;

ods html select all;                              
 
options printerpath=gif animation=stop;               /* stop recording images */
ods printer close;

 

 

 

 

Anim3.gif 

Rick_SAS
SAS Super FREQ

Great. In addition to setting a common axis range, the "prepend fake data trick" is useful for obtaining a consistent sort order for categorical variab... and assigning common attributes. You can also append data to overlay special points.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 22 replies
  • 4470 views
  • 3 likes
  • 5 in conversation