PROC MEANS - Save table shown in results and not in Output Data - sas

I have the following code to produce descriptive statistics:
proc means data=sashelp.cars;
var Horsepower Weight Length;
output out = cars_stats mean = std = /autoname;
run;
I would like to get the table shown in the Results tab in the Output Data as I export the tables to Excel later on.
At the moment I get the following in the results:
But I get this in the Output Data tab.
How could I get the table from the Results in the Output Data?

Proc MEANS with option STACKODSOUTPUT will produce the same desired table.
ods select none;
proc means data=sashelp.cars stackodsoutput;
var Horsepower Weight Length;
ods output summary = cars_stats_stacked;
run;
ods select all;

ods to the rescue!
First run your code like this:
ods trace on;
proc means data=sashelp.class;
var Weight Height;
output out = class_stats mean = std = /autoname;
run;
ods trace off;
Then check the log:
Output Added:
-------------
Name: Summary <-- We want this bit
Label: Summary statistics
Template: base.summary
Path: Means.Summary
-------------
Then re-run like this:
ods select none;
ods output summary = class_summary;
proc means data=sashelp.class;
var Weight Height;
output out = class_stats mean = std = /autoname;
run;
ods select all;
This approach allows you to capture any output from any proc that would normally be displayed in the results area as a sas dataset instead.

Related

Create a variable dataset out of proc contents

How to use ODS TRACE to identify name of the PROC CONTENTS results output object that contains the variable name, type, length, format and informat, and save these results as new SAS datasets.
my code:
ods select Variables;
proc contents data=mylib.hotel1 out=work.h1;
run;
ods select default;
but output dataset is different from result.
There is no need to select the ODS table since out= already contains this information. If you really do want to use ODS, you can identify the table in the log with ods trace.
ods trace on;
proc contents data=sashelp.cars;
run;
ods trace off;
Check the log and you will see the dataset containing all variables:
Output Added:
-------------
Name: Variables
Label: Variables
Template: Base.Contents.Variables
Path: Contents.DataSet.Variables
-------------
You can save this with the ods output statement in proc contents.
proc contents data=sashelp.cars;
ods output variables=variables;
run;
You will receive an output dataset called variables.

Output distribution charts in a pdf format? I only need the chart from a proc univariate of all the variables in a table

How can I output distribution charts in a pdf format? I only need the chart from a proc univariate of all the variables in a table - not any additional metrics.
ods pdf file="aaaa.pdf
TITLE 'Summary of Weight Variable (in pounds)';
PROC UNIVARIATE DATA = sashelp.class NOPRINT;
HISTOGRAM _all_ / NORMAL;
RUN;
ods pdf close
You use ODS SELECT _chartname_ to limit the output to what you want. You need to remove the NOPRINT option though or no output is generated to display regardless of destination.
It looks like univariate produces: CDFPlot, Histogram, PPplot, Probplot, QQplot so assuming you want just the histogram add the following line to your code:
ods select histogram;
Full code:
ods pdf file="aaaa.pdf;
ods select histogram;
TITLE 'Summary of Weight Variable (in pounds)';
PROC UNIVARIATE DATA = sashelp.class ;
HISTOGRAM _all_ / NORMAL;
RUN;
ods pdf close
Add it before or within your PROC UNIVARIATE.
PS. You're missing a semicolon on your ODS PDF statements at the top and bottom.
A good blog post from the SAS website on this is available here.

Outputting p-values in SAS Proc Autoreg Procedure

i am able to output all sorts of statistics and values, however, am missing the ability to output p-values of parameter estimator significance.
I do get them in the Output window but not in my outputted tables. Here is my code
ods output PhilOul = philipps FitSummary = Stats;
proc autoreg data=ppnr_1.train outest=regression_13;
model mnos = ir_irs10y_yoyd ur_ap_yoy sav_yoyd_l1
/ stationarity=(PHILLIPS)
;
where date ge "&dev_start." and date le "&dev_end." ;
proc print data = regression_13;
run;
quit;
As you can see, I get DW-statistics (in "Stats" table), PhilipsOulier ("Philipps" table) and parameter estimates ("Regression_13") but not the significance of these parameters...
Best regards, Niels
EDIT: I used to figure out how to output p-values in PROC REG statement. Specify the TABLEOUT option. However, this option is not valid in PROC AUTOREG :-(
The p-values are in ODS output table ParameterEstimates. Change your code to be:
ods output
PhilOul = philipps
FitSummary = Stats
ParameterEstimates = Estimates
;
You can observe the ODS output tables that a procedure creates by using ODS TRACE. You only need to trace once, or if you forget :).
ODS TRACE ON;
PROC ...;
ODS TRACE OFF;

How to clear "Results" from Proc Univariate to show only a specific table

I´ve been using the UNIVARIATE proccedure in order to get the p-value from a series of distributions (lognormal, exponential, gamma) and have reached the following problem:
I am using the following code to get the p-values of the goodness of fit tests for each of the distributions:
ods select all/*ParameterEstimates GoodnessOfFit*/;
proc univariate data=results.Parametros_Prueba_1;
var Monto_1.;
histogram /
lognormal (l=1 color=red SHAPE=&ParamLOGN2_1 SCALE=&ParamLOGN1_1)
gamma (l=1 color=red SHAPE=&ParamGAM1_1 SCALE=&ParamGAM2_1)
exponential (l=2 SCALE=&ParamEXP1_1);
ods output GoodnessOfFit=results.Goodness_1;
run;
proc print data=results.Goodness_1;
After running the previous code I get the "Results" which gives me the histogram graphic and other descriptive information about the tests. I am looking for a way to get this "Results" print to show only the last part corresponding to the "proc print" added on the last line.
Thanks in advance!
If you want no output to the screen (results window) from PROC UNIVARIATE, then the simplest answer is:
ods select none;
proc univariate ... ;
run;
ods select all;
proc print ... ;
run;
ods select none; tells ODS to not make any ODS output whatsoever. You'll still get your ODS OUTPUT though as that comes in afterwards.
ods select none;
proc univariate data=sashelp.class;
var height;
histogram name='univhist' /
lognormal (l=1 color=red )
gamma (l=1 color=red )
exponential (l=2 );
ods output GoodnessOfFit=Goodness_1;
run;
ods select all;
proc print data=Goodness_1;
run;
Now, you'll note you don't get your histogram; that one is harder. It unfortunately changes its name every time you run it, and even if you use the NAME= option, that'll only work the first time it's run. You need to use PROC GREPLAY to delete it.
proc greplay nofs igout=work.gseg;
delete 'univhist';
run; quit;
(Assuming UNIVHIST is the name you assign it.)

How to save regression coefficients to file in SAS?`

I am trying to carry out a logistic regression with SAS. I have few settings for the model, and try to compare the difference.
What I want to archieve is to output the estimated coefficients to a file. I think ODS maybe a promising way, but don't know how to use it.
Can anyone write me a simple example?
Thank you very much.
To add a bit of additional color; ODS OUTPUT <NAME>=DATASET ... ; will save the output into the specified dataset.
Use ODS TRACE get the names of output tables. Information on the tables will be written to the log.
ods trace on;
ods output ParameterEstimates=estimates;
proc logistic data=test;
model y = i;
run;
ods trace off;
For Logistic:
proc logistic data = in descending outest = out;
class rank / param=ref ;
model admit = gre gpa rank;
run;
For proc reg:
proc reg data=a;
model y z=x1 x2;
output out=b
run;
for proc glm:
ods output Solution=parameters FitStatistics=fit;
proc glm data=hers;
model glucose = exercise ;
quit;
run;
for proc reg this doesn't work for me
Use proc reg OUTEST=b
proc reg data=a outest=b;
model y=x1;
run;
other reg can get other parameters added to OUTEST.