SAS ODS output formatted weird - sas

I'm trying to export a content to Excel. I use the below code but my output excel formatting is horrible.
ods excel file= "&cur_path/&project_name._Proc_Means.xlsx" style=printer ;
proc means data=&this_lib..&this_data;
run;
ods excel close;
The output looks like
The huge blank gap makes the file unreadable. I also find out that it puts all the outputs in the same row instead of many different rows.
Any suggestions on how to fix it?
Thanks in advance.

Assuming you have SAS 9.3+, which you must to use ODS EXCEL, you can add the stackodsoutput option to the PROC MEANS statement; that will give you a much more nicely formatted sheet.
ods excel file= "c:\temp\Proc_Means.xlsx" style=printer ;
proc means data=sashelp.cars stackodsoutput;
run;
ods excel close;
If you have prior to 9.3, you may want to use the OUT= option in PROC MEANS and then output the dataset yourself using PROC EXPORT or PROC PRINT. The default PROC MEANS ODS output is not very table-friendly.

Related

ods excel and proc template

I am running into an error when trying to use ods excel after defining a style named excel via ods template. I was wondering if anyone could explain why this is happening as I thought ods styles and ods destinations were two completely separate things.
The following ods excel statement works fine:
ods excel file="%sysfunc(pathname(work))\x.xlsx";
proc print data=sashelp.class;
run;
ods excel close;
But if I try to run it after running the below proc template code, I get an error.
proc template;
define style excel;
parent=styles.htmlblue;
class graph / attrpriority='none';
style graphdata1 / contrastColor=#416FA6 markersymbol='circlefilled';
style body from body / pagebreakhtml=_undef_; * REMOVE THE HORIZONTAL RULE;
end;
run;
ods excel file="%sysfunc(pathname(work))\x.xlsx";
proc print data=sashelp.class;
run;
ods excel close;
The error is:
ERROR: Could not find method.
ERROR: No body file. EXCEL output will not be created.
I can just rename my style to something other than excel to fix the issue, but I don't understand why this is happening in the first place. Is anyone able to explain? Thanks.
From comments, thanks #Tom:
Use ods styles.excel instead of ods excel:
ods styles.excel file="%sysfunc(pathname(work))/x.xlsx";
proc print data=sashelp.class;
run;
ods styles.excel close;

SAS ODS Query/Statement print along with it's output

SAS EG
Is there any way I can print the query/statement used to get the output, along with the output, using SAS ODS?
Suppose,
ods pdf file=pdfile;
proc sql;
select a.*
from tab1 a inner join tab2 b
on a.something=b.something
where <>
having <>;
quit;
ods _all_ close;
this would print the OUTPUT generated from the above query. But can I also get the query printed via the ods pdf along with the output?
There's no automatic way to redirect the log that I'm aware of.
There are a few ways to get what you want, however.
First off, if you are able to use Jupytr, SAS has plugins to enable that to work with SAS, and then you can simply write in the notebook and run the code, and the results appear with your code just as you want. See Chris Hemedinger's blog post on the subject for more details.
Second, SAS Studio will support a notebook-style interface probably with the next major revision (I believe version 5.0) which will release late next year. So similarly, you would put your code and get your output in the same windows.
Finally, the third option is to do as Reeza suggested - write to a log file, then print that to the output. It's messy but possible.
Here's an example of the latter. I don't make any effort to clean it up, note, you'd probably want to remove the logging related to PROC PRINTTO and the otehr notes (or turn on NONOTE).
ods pdf file="c:\temp\test.pdf";
filename logfile temp;
proc printto log=logfile;
run;
proc sql;
select * from sashelp.class;
quit;
proc printto;
run;
data _null_;
infile logfile;
input #1 #;
call execute(cats('ods text="',trim(_infile_),'";'));
run;
ods _all_ close;

How to have multiple graphs generated by one gplot procedure output to a single PDF file?

The following GPLOT procedure generates many graphs(It gives sales by different product). Say if my product has 'Sofa', 'bed', 'Chairs', it will give 3 graphs, one for sofa, one for chairs, one for bed.
I'd like to have all the three graphs generated to be output to one single PDF file. I tried the following, but it only keep the last graph generated. Any ideas how I can do this?
ODS PDF FILE= 'OUTPUT.PDF';
PROC GPLOT data = AB.TEMP;
plot sales*Months=Product;
by Region;
run;
ODS PDF CLOSE;
Thanks!
Sandwich your code between ODS PDF and ODS PDF CLOSE statements.
ODS PDF FILE='my_file.pdf' style=meadow;
PROC GPLOT data = AB.TEMP;
plot sales*Months=Product;
by Region;
run;
ODS PDF CLOSE;
Does this work for you? If so, then you have something wrong in your code. Post your code and log in that case.
proc sort data=sashelp.cars out=cars;
by origin;
run;
ods pdf file="C:\_localdata\temp.pdf" style=meadow;
proc gplot data=cars;
plot mpg_city*msrp=make;
by origin;
run;
ods pdf close;

2 proc print output in the same page (listing or rtf)

I am running two proc print and would like to compare them visually on the SAS listing output. Both proc print prints only 3 observations.
The issue is I can't have the 2 output in one and same page...I have to scroll down for one page to another page to look at the other output. I have tried option pagesize=MAX but it doesn't work (MIN neither)...Is there a way to achieve what I want ?
I was wondering if an ODS statement redirecting to RTF or (PDF) would do that ?
Thanks in advance
sas_kappel
Both ODS destinations can give you this, using the startpage=never option, which tells SAS not to start a new page when a new procedure is run.
These output to a results window, rather than the listing output.
option obs=3;
ods pdf startpage=never;
proc print data=sashelp.class;
run;
proc print data=sashelp.class;
run;
ods pdf close;
option obs=max;
For the listing destination, you can replace the pagebreak with another character (e.g. a space) by using the option: option formdlim=' ';.
Thanks Keith.
And would it be possible to have it directly in my output sas window ? I was thinking the ods statement ( as I only need the listing output) It doesn't seems to work:
option startpage=never obs=3;
proc print data=sashelp.class;
run;
proc print data=sashelp.class;
run;
option obs=max;
So I guess there is no other option to achieving this other than ODS statement ?

Output values to excel in sas

Can some one please help me to output the data generated from the following code(yt) to an excel data set?
proc iml;
d = 0.4;
call farmasim(yt, d) n=10 sigma=2 seed=123457;
print yt;
run;
ods tagsets.excelxp file="myfile.xml";
proc iml ... etc. ... quit;
ods tagsets.excelxp close;
For more info google "tagsets.excelxp" or see http://support.sas.com/rnd/base/ods/odsmarkup/excelxp_demo.html
Alternately, you can move yt into a dataset, and use PROC EXPORT, either to EXCEL if you have ACCESS to PC FILES licensed, or to CSV if not.