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;
Related
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.)
In the following code, I would like to print an excel sheet and do not open it once the code ends, does anyone know how to do this because the ods excel close does not work. There is an option in the SAS 9.4 platform to not open the output but when I choose than and open a new SAS session the option is reverted. Anyone knows something about it? Thanks :)
ods listing close;
ods excel file="path.xlsx"
/*ods excel file="path.xlsx"*/
/* will apply an appearance style */
/*style=calibri*/
options(
/* for multiple procs/sheet */
sheet_interval="none"
/* name the sheet tab */
sheet_name="filename"
);
/* add some formatted text */
ods escapechar='~';
ods text="~S={font_size=14pt font_weight=bold}~filename";
proc print data=data noobs;
run;
ods excel close all;
ods listing;
Tazz:
Problem
You should look at the SAS log for ERROR messages. In future questions be sure to add ERROR messages. Do you get this message ? (### is the source code line number)
### ods excel close all;
---
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, ANCHOR, AUTHOR, BOX_SIZING,
CATEGORY, CLOSE, COMMENTS, CSSSTYLE, DOM, DPI, FILE, GFOOTNOTE, GTITLE, IMAGE_DPI,
KEYWORDS, NOGFOOTNOTE, NOGTITLE, OPTIONS, SASDATE, STATUS, STYLE, TEXT, TITLE,
WORK.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
So, this statement of yours is invalid
ods excel close all;
Fix
Use instead either
ods excel close;
or
ods _all_ close;
Be forewarned, the first time you run the code Excel will open the output. If you leave the results open in Excel and run the code again you will get a different ERROR:
ERROR: File is in use, ....
because the destination will still be open and SAS will not be able to write to it.
Turn off results viewing
ODS RESULTS OFF;
The ODS destination will be written to. The automatic viewing of results and results tracking as new items in the Results tab will not happen.
The setting is not programmed in, it's in the GUI.
Tools>Options>Preferences>Results
Uncheck: View results as they are generated
I have this Macro A. Everytime I run it, I get a result as the image below (include 2 tables and 1 graph). Note that this time I copied them from SAS output window and paste it on Excel then format it manually. My question is, when I run Macro A multiple times, how can I export all the results to a single specific Excel Sheet, one after another automatically?
Since I'm kinda a beginner in SAS, so a simple solution is preffered :)
Thanks a bunch!!
SAS result in excel
Use ODS Excel and sheet_interval option. This assumes SAS 9.4+
Ods excel file='myfile.xlsx' options(sheet_interval='none') style=meadow;
%macro_run();
Ods excel close;
Within the macro you may need to add:
Ods excel options(sheet_interval='none');
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;
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.