Create a variable dataset out of proc contents - sas

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.

Related

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;

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

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.

SAS- Supress Results view on some, but not all, proc print ods outputs

I want to be able to print all of my reports to external files but only display a select few in the results viewer. In the below example I want reportA and reportB to be displayed AND printed (file.xls) but reportC to be printed to a separate file (file2.csv) and not displayed in the results viewer. Any ideas?
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
ods csvall file="/file/file2.csv";
proc print data=reportC;
run;
ods csvall close;
You can also use ODS EXCLUDE and ODS SELECT to target specific destinations.
For example, ods html select none; will turn off the HTML destination temporarily, but not actually close it - it just won't get any results for a while. You can then use ods html select all; to turn it back on.
You can also use ods html exclude all; to do the same thing and then turn it back on with ods html exclude none;.
With either statement, you can also use a where statement in the ods select/exclude to filter to only affect one specific part of an output. See the documentation for more details.
Close the list output which is the default. OR the HTML if that is the default results window in your system. Re-open the output after the file is created.
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
ods listing close;
ods html close;
ods csvall file="/file/file2.csv";
proc print data=reportC;
run;
ods csvall close;
ods listing;
ods html;
I actually found a better solution through using the proc export feature for suppressing display of the csv output.
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
proc export data=reportC
outfile="/file/file2.csv"
dbms=dlm
replace;
delimiter=",";
run;
Thanks for the help #Reeza I'll keep those settings in mind for future projects.

Suppressing HTML output in SAS

I'm trying to suppress HTML output and get PROC PRINT to output only to CSV, but ODS HTML Close doesn't seem to work.
My code is:
ODS HTML close;
ODS CSV file="\\..output folder..\filename.csv";
proc print data=test;
run;
ODS CSV close;
ODS HTML;
Your approach seems a bit odd, why resort to ods csv?
SAS has a proc export procedure:
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace;
run;
You can further configure it to have a different delimiter, no headers etc.: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000393174.htm
EDIT
In reply to your comment: i see two ways around the issues that keep you from trying proc export.
The first approach is setting the validvarname to ANY, which gives you great liberty in choosing variable names. E.g.:
options validvarname=ANY;
data test;
'Column Header Text I Want'n=1; output;
'Column Header Text I Want'n=5; output;
run;
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace;
run;
Personally, i'm not a fan of the above approach, since i find that it leads to harder-to-read code when you no longer have some naming rules for variables.
A second approach - which i prefer - is to label the variable with the text you want it to have and put the label option on your proc export. E.g.:
data test;
label variable_name='Column Header Text I want';
variable_name=1; output;
variable_name=5; output;
run;
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace LABEL;
run;
Note that there is a small distinction in the output: the first approach will not put quotes around your column names while the second approach will do that.
Finally, while doing some extra reading myself, i stumbled across this, which may be of help to you as well: http://www.sascommunity.org/wiki/Create_a_CSV_file_without_column_names/headers_in_row_1#DATA_NULL_with_a_PUT_statement.2C_all_fields_quoted
I'm been trying all day and finally got it for me. What I wanted suppress from the results viewer is just below here (and the end of a macro). The results I wanted in the results viewer and now called in a separate macro at the end...
Brubumski
ODS HTML close; * bsk;
ods results off; * bsk;
ods csvall file="&file1";
proc print data=tr_outds noobs; run;
ods csvall close; * bsk;
ods results on; * bsk;
ODS HTML; * bsk;
%OdsOn1(outds,outds2,tr_outds, file1, file2); * bsk;
%mend process_input_data_10_10;
%macro OdsOn1(outds,outds2,tr_outds, file1, file2);
proc freq data=outds;tables Group_nm/missing;run;
proc freq data=outds2;tables case_id/missing;run;
proc print data=tr_outds(obs=10) noobs; run;* bsk;
ods csvall file="&file2";
proc print data=cases noobs; run;
ods csvall close;
%mend OdsOn1;
Ah, I've found out the problem. The results window will still display HTML output which will really slow the program down as ODS HTML CLOSE seems to only affect ouput to a specific file, not the results window.
In order to stop that, I should have used ODS RESULTS OFF; instead.
ODS RESULTS OFF;
ODS CSV file="\\..output folder..\filename.csv";
proc print data=test;
run;
ODS CSV close;
EDIT: It seems that ODS RESULTS cannot be turned on and off at will to cause only certain PROC PRINT statements to generate outputs. This is really annoying for me, so I'm going with Shorack's PROC EXPORT methods.