SAS Proc Report spacing= option not working - sas

I'm doing some examples to learn the basics of proc report. For some reason I can't get the spacing= option to work, how do I fix it and what are the most used simple options to format the appearance of columns?
p.s I'm using SAS Studio
proc report data = ads2;
columns subjid b c;
define subjid / display 'Subject ID' spacing=4;
define b / display 'One' spacing=4;
define c / display 'Two' spacing=4;
run;

The spacing= option is only applicable to ODS LISTING destination.
From the DEFINE Statement documentation:
SPACING=horizontal-positions
defines the number of blank characters to leave between the column being defined and the column immediately to its left. For each column, the sum of its width and the blank characters between it and the column to its left cannot exceed the line size.
Default: 2
Restriction: This option has no effect on ODS destinations other than the LISTING destination.
Start learning more about REPORT styling from the documentation "Using ODS Styles with PROC REPORT"
Most Base SAS procedures that support ODS use one or more table templates to produce output objects. These table templates include templates for table elements: columns, headers, and footers. Each table element can specify the use of one or more style elements for various parts of the output. These style elements cannot be specified within the syntax of the procedure, but you can use customized styles for the ODS destinations that you use. For more information about customizing tables and styles, see "TEMPLATE Procedure: Creating a Style Template" in SAS Output Delivery System: Procedures Guide.

if I understood correctly you want to set the cell width:
proc report data=sashelp.class;
col name age sex;
define name / style(column)=[cellwidth=2in];
define age / style(column)=[cellwidth=5in];
define sex / style(column)=[cellwidth=.5in];
title "Using the CELLWIDTH= Style with PROC REPORT";
run;
If you want read more from this option : https://documentation.sas.com/?docsetId=proc&docsetTarget=p1sh52tpsi1nxbn1sr371jj0bngj.htm&docsetVersion=9.4&locale=en#p1sh52tpsi1nxbn1sr371jj0bngj

Related

I don't see an explanatory legend in SAS proc freq

I have a problem with the legend not being visible at cross tabulation in porc freq in SAS. How can I show it?
I see only a table:
But I want to also see a legend:
PROC FREQ does not have a legend per se, but you can use the title statement to put some information there, or footer.
If you want better control, use PROC TABULATE which has substantial ability to customize the output, including the box option which places whatever information you want in the top-left corner of the table.
If you run the following:
proc template;
source Base.Freq.CrossTabFreqs;
run;
Then check your log, you should see:
define crosstabs Base.Freq.CrossTabFreqs;
notes "Crosstabulation table";
cellvalue Frequency Expected Deviation CellChiSquare TotalPercent Percent RowPercent ColPercent CumColPercent;
header TableOf ControllingFor;
footer NoObs Missing;
If you do not, that means that someone has modified your PROC FREQ base template and that's why it's not showing. In this case you would need to replace your default SAS installation templates by obtaining clean copies from a different source. It may also need to align with your SAS version.
If you have a colleague or different SAS installation that is operating as expected, you can run the PROC TEMPLATE above, then copy the code from the log and re-create the template as:
proc template;
<insert copied code from log>;
run;
And you probably realize, but this is why modifying templates is generally a last resort for customizing data/output and usually you should never modify the default templates.

SAS Enterprise Guide - Export Temporary "WORK" table Into Multiple Worksheets in Same Workbook Based on Criteria

I've searched and searched, but I can't seem to find a solution.
I'm on 8.2 Update 4 (8.2.4.1261) (32-bit).
Can someone help me export a table into an Excel file with multiple sheets?
Example: Table contains a list of USA professional sports teams (with their city/nickname and league they are in). Each tab would be separated by league (NBA, MLB, NFL, NHL, MLS). How would I go about this?
I'd also like to add the current date to the output Excel file name. From what I've read, I can create a variable with the sysdate. Just not sure how to incorporate it in the code.
Each sheet name is to be based on a group.
In SAS we use the BY statement to specify the variable(s) that form a group -- in your case, it is the one variable league
The BY statement makes special tokens available during output, #BYVAR<n> and #BYVAL<n>
You want the value of the league to be important (sheet name) during output so #BYVAL1
ODS EXCEL sheet name construction is specified in the OPTIONS option. You can use the BY token in the option.
You want ODS EXCEL ... OPTIONS (sheet_name="#BYVAL1") ...;
A BY statement in output procedures produces an extra line <BYVAR>=<BYVAL> which would be noise in your Excel output.
Prevent the noise with OPTIONS NOBYLINE;
Example:
ods excel file='output.xlsx' options(sheet_name="#BYVAL1");
options nobyline;
proc print noobs data=sashelp.cars;
by make;
run;
ods excel close;
Produces
More
If you want the BY variable to appear in the PROC PRINT output use a VAR _ALL_; statement, or list the columns wanted explicity.
Adding the BY variable to the output will make things easier if you need to import and combine data that was edited in Excel, or if you are making various charts and such. In reality you might be better of producing a single worksheet with all the data and then using autofilter (which is an ODS EXCEL option) and Excel pivot tables/charts if you are doing other work in Excel. (Proc TABULATE and REPORT can do a very large subset of what pivot tables can do.)

SAS RobustReg Procedure output parameter estimates [duplicate]

Running complex procs such as PROC REG or PROC GLM, there are often tables that are produced in the output window describing the results of the regression, in addition to the output datasets produced using OUT or OUTPUT options.
How can I output those tables to SAS datasets?
For example, given the first SAS example in PROC REG (on the documentation page), how can I output the Goodness of Fit Statistics (such as the R-Squared)?
In order to identify possible output datasets, SAS provides the ods trace statement. This asks SAS to write to the log the name (and some details) of each data table it writes to the output. In most cases, this can be saved to a dataset via ods output.
For example, in the SAS example referred to in the question, you could write:
ods trace on;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
ods trace off;
That would report in the log that "FitStatistics" is the name of the output object you want. Then you write:
ods output FitStatistics=fitds;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
and it will output the fitds dataset.
ODS Trace is only needed for the purpose of determining the name of the table of course - once you know the name of the table you need, you can simply use that name with ods output in the future.
You also frequently can find the list of the table names in the documentation; for example, PROC REG places them here.
ODS Output may be placed any location before the run statement (as it is a global statement); a common location is immediately before run. My personal preference is to put it before the proc as it is a global statement, but there is some disagreement with that approach.

How do I see what output options are available in my proc?

Running complex procs such as PROC REG or PROC GLM, there are often tables that are produced in the output window describing the results of the regression, in addition to the output datasets produced using OUT or OUTPUT options.
How can I output those tables to SAS datasets?
For example, given the first SAS example in PROC REG (on the documentation page), how can I output the Goodness of Fit Statistics (such as the R-Squared)?
In order to identify possible output datasets, SAS provides the ods trace statement. This asks SAS to write to the log the name (and some details) of each data table it writes to the output. In most cases, this can be saved to a dataset via ods output.
For example, in the SAS example referred to in the question, you could write:
ods trace on;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
ods trace off;
That would report in the log that "FitStatistics" is the name of the output object you want. Then you write:
ods output FitStatistics=fitds;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
and it will output the fitds dataset.
ODS Trace is only needed for the purpose of determining the name of the table of course - once you know the name of the table you need, you can simply use that name with ods output in the future.
You also frequently can find the list of the table names in the documentation; for example, PROC REG places them here.
ODS Output may be placed any location before the run statement (as it is a global statement); a common location is immediately before run. My personal preference is to put it before the proc as it is a global statement, but there is some disagreement with that approach.

SAS column width for HTML output

I am trying to make adjustments to my HTML output from SAS ODS.
This is all I have:
ODS HTML FILE = 'C:\filename.html' options(pagebreak='no');
proc print data=dataset noobs;
run;
ODS HTML CLOSE;
RUN:
Ideally, I would just have columns have an autofit if possible.
Any help is appreciated.
Take the default style, and modify it so that the DATA style element (see documentation here) has the white-space:nowrap CSS style applied to it. Save the changes to a new style called 'my_style'.
The white-space:nowrap is the bit of magic that will force the text not to line-break once it gets too long.
proc template;
define style my_style;
parent = styles.default;
style data from data / htmlstyle="white-space:nowrap";
end;
run;
Print out the table using out new modified style:
ods html style=my_style;
proc print data=sashelp.webmsg;
run;
ods html close;
Some more notes.... Sometimes SAS will actually support the actual CSS style that you need to change in which case you should use that (instead of htmlstyle=). Find the complete list here.
Also, your default style may not actually be named styles.default. To find the name of your default style, go to Tools->Preferences->Results and get the name from the 'Style' dropdown box. This is for the base SAS editor. For EG, it may be slightly different but I'm sure you'll be able to find it.