SAS column width for HTML output - sas

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.

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 Proc Report spacing= option not working

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

Sas Results Viewer - Start at top of new output

This is another usability oriented question for me...
Is there a way to have the results viewer "auto-position" itself at the top of the most recent output when something new is submitted?
Sometimes the results viewer shows the bottom of the just-generated table. Sometimes, it shows the top of a table, but not of the "topmost" table (i.e. in the middle of new results).
This behavior is akin to surfing the web and having chrome open a new webpage at the bottom... it really doesn't make sense and takes time away from viewing the results while trying to find the actual top of the new results, which can sometimes be very long and mixed up with other previous results.
A partial workaround, is to have the logs/results viewer clear during each run, which at least makes it easy to page to the top of the current results, but I still have to actually page up, which just seems silly. Here is what I use to clear logs and the output viewer from the code. Is there a better set of commands to use?
*Clear prior run's result viewer list and log window*;
ods html close; /* close previous */
DM log "OUT;CLEAR;LOG;CLEAR;" log continue ;
DM log 'next results; clear; cancel;' whostedit continue ;
ods html; /* open new */
You can! By understanding that:
ODS HTML destination generates HTML source that has the default anchor <ANAME=IDX#n> before each proc's output. The anchor name prefix can be altered with the ODS HTML ANCHOR= option.
Proc TEMPLATE can be used to create a custom style that utilizes a style attribute such as POSTHTML to inject a HTML snippet into the destination that is JavaScript code.
The injected JavaScript can assign location.hash to the expected initial anchor name. This will force the browser to navigate to that anchor.
Example:
proc template;
define style topnav; /* name of style to specify when opening ODS HTML */
parent=styles.htmlblue; /* name of style to use for thematic desire */
/* JavaScript to be injected into destination */
style body from body /
posthtml="<script>location.hash='#IDX';</script>";
end;
run;
ods html
path="C:\temp"
body="sample.html"
style=topnav /* specify the custom style */
;
proc print data=sashelp.cars;
run;
proc print data=sashelp.class;
run;
ods html close;

Display parameter estimates in table format

I'm using SAS for the first time and am unable to find out how to display parameter estimates for a regression analysis in table format. Currently it just spits out fixed-width text in the output window.
Any help would be appreciated, thanks!
Lots of ways to do this. The easiest is to use HTML as your output destination. The results will then be displayed in an HTML table.
ods html; *Turns on the HTML output. Look at SAS doc on how to set styles, locations, etc;
<your code here>
ods html close; *Turns off the HTML output;