SAS ODS Documentation Syntax Error - sas

I have many questions regarding the ODS system and am trying to educate myself. However, I am unable to do so as the SAS documentation example generates an error.
The documentation in question is Controlling Where Your Output Is Stored.
The very first example is, verbatim,
/* Specify the ODS output path */
filename odsout ".";
goptions reset=all;
ods _all_ close;
ods pdf path=odsout file="mygraph.pdf";
proc gchart data=sashelp.prdsale;
vbar Product / sumvar=actual;
title1 "First Quarter Sales in Canada";
where Quarter=1 and Country="CANADA";
run;
quit;
ods pdf close;
ods html; /* Not required in SAS Studio */
It appears that the "." in the filename statement is a place holder akin to "C:\your\file\path\here\".
I have replaced that with "C:\output". When I do this, I get the following error:
6 ods pdf path=odsout file="mygraph.pdf";
----
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, (, ANCHOR, AUTHOR, BACKGROUND, BASE,
BODY, BOOKMARK, BOOKMARKGEN, BOOKMARKLIST, BOX_SIZING, CLOSE, COLOR, COLUMNS, COMPRESS,
CONTENTS, CSSSTYLE, DISPLAY, DOM, DPI, EXCLUDE, FILE, FONTSCALE, GFOOTNOTE, GTITLE,
HOST, KEYWORDS, NAMED_DEST, NEWFILE, NOBACKGROUND, NOBOOKMARKGEN, NOBOOKMARKLIST,
NOCOLOR, NOCONTENTS, NOGFOOTNOTE, NOGTITLE, NOPDFNOTE, NOTOC, PACKAGE, PCL, PDF,
PDFMARK, PDFNOTE, PDFTOC, PRINTER, PS, SAS, SELECT, SGE, SHOW, STARTPAGE, STYLE,
SUBJECT, TEXT, TITLE, UNIFORM.
ERROR 76-322: Syntax error, statement will be ignored.
Am I doing something wrong or did the author of this example not compile before publishing?

It seem that path option is valid in ods html, but is not valid in ods pdf, but it doesn't matter because you can specify absolute path in file option.
ods pdf file="C:\temp\mygraph.pdf";

Related

HTML output in SAS

I only see results of my SAS programs in Log like:
16488 title '6';
16489
16490 ods html file = 'E:\Dev\ka\body1.html';
16491
16492
16493 proc means data=learn.blood;
16494 var RBC WBC;
16495 output out = means mean = M_RBC M_WBC;
16496 run;
It's not show any error, but I don't see results in html file.
How to turn on html output?
You may have the setting 'Show results as they are generated' off.
Check your preference settings.
Confirm your HTML file is created as well, though you may need to include a CLOSE before it is fully available.
ods html file = 'E:\Dev\ka\body1.html'
proc means data=sashelp.class;
var height weight;
output out=means mean=M_Height M_Weight;
run;
ods html close;
Works fine for me. I adapted your code slightly to test it:
ods html file="%sysfunc(pathname(work))\body1.html";
proc means data=sashelp.class;
var height weight;
output out=means mean=M_Height M_Weight;
run;
%put Your file has been output to: %sysfunc(pathname(work))\body1.html;
I am seeing results. Are you sure you have observations in your dataset and that there are no errors or warnings being printed to the log?

The date and the time that SAS program started are printed at the top of each page in listing output, why are not printed on html output?

options date/nodate;
This option has no effect on my html output but it works fine on listing output. Also explain how to print date time on html output same like listing output?
/*----prints date in the upper right side of the output------*/
options dtreset date;
ods listing;
Title; /*I dont want to print any title*/
proc print data=sashelp.class;
run;
ods listing close;
/*----for html ods, date is not printed----------------------*/
options dtreset date;
ods html;
Title; /*I dont want to print any title*/
proc print data=sashelp.class;
run;
ods html close;
Working as designed; according to the documentation:
Note: In an interactive SAS session, the date and time are noted only in the output window.
Output window means the listing destination, by the way (separate from the Results Window which is where modern ODS destinations, including HTML, go).
If you want it in HTML, you'll need to add it to the title:
title "(other things) &sysdate.";
Or &Sysdate9. if you prefer that format.
Some other ways to do this are discussed in Art Carpenter's Placing Dates in Your Titles.

ODS PDF - Two columns of output interrupted by one column of output on a single page

I'm trying to create an output for a requestor that wants me to take a preexisting report that comes in two columns on a single page and break it apart on that single page into different subsections, which they want indicated by a new title in the middle of the page where the new subsection begins.
What I have right now is:
ods pdf file=_pdf_ newfile=none startpage=no columns=2 notoc contents=no
style=swsp;
ods text = 'EMPLOYER RENEWAL DATA';
proc report data=renewal_data;
...
run;
ods startpage=now;
ods text='FINANCIAL DATA (FULL PROGRAM YEAR)';
proc report data=financial_data_total;
...
run;
ods startpage=now;
title1 '$ACA_YR_STR. ACADEMIC YEAR DATA';
footnote;
ods text='APPLICANT DATA';
...
run;
What I want is the page to have a section title where the second ods startpage=now is located that treats the entire page as one column, but then returns to two columns for the remainder of the page.
Thanks!
If you have SAS 9.4 (and possibly 9.3), you can use ODS LAYOUT to achieve this pretty easily. You need to create a gridded layout, and then change your title to another ODS TEXT (which you can of course style to be like a title). Titles go with PROCs, not by themselves, so if you actually use title it will appear where the next PROC REPORT goes, not in its own area.
Here's a barebones example that might get you started. See the ODS REGION and ODS LAYOUT documentation for more information. Note, this is something that is in production, but is also in active development, so different versions of SAS (including newer ones) may change how some of this works (though hopefully not break formerly existing functionality, who knows).
ods pdf file="c:\temp\test.pdf" startpage=no newfile=none notoc contents=no
style=swsp;
options obs=10;
ods layout gridded columns=2 rows=3;
ods region row=1 column=1;
ods text = 'CLASS DATA';
proc report data=sashelp.class;
columns name age;
run;
ods region row=1 column=2;
ods text='CAR DATA';
proc report data=sashelp.cars;
columns make model;
run;
ods region column_span=2 row=2 column=1;
ods text='ACROSS THE WHOLE PAGE NOW';
footnote;
ods region row=3 column=1;
ods text='NOT ACROSS WHOLE PAGE FOR THIS PART';
proc report data=sashelp.baseball;
columns name team;
run;
ods layout end;
ods pdf close;

Print superscript or subscript in SAS without ODS

This can be achieved using ODS, but I have a constraint that I am not supposed to use ODS as I'm using Listing. I need to generate RTF reports which has super and subscript text in them. Below is the sample code which I was referring which uses ODS.
ods rtf file='temp.rtf';
ods escapechar='^';
proc print data=sashelp.class;
title 'this value is superscripted ^{super 2} ';
title2 'this value is subscripted ^{sub 2} ';
run;
ods rtf close;
I want to print superscript or subscript text in Proc report title or footnotes.
Silly constraint calls for equally silly solution - who needs ODS escapechar when you can hard-code the rtf control sequences for subscripts and superscripts?
x 'cd c:\temp';
/*Produce initial rtf without superscripts / subscripts*/
ods rtf file='temp.rtf';
proc print data=sashelp.class;
title 'this value is superscripted 2';
title2 'this value is subscripted 2';
run;
ods rtf close;
/*Add them in manually as per .rtf file format specification*/
data _null_;
infile "c:\temp\temp.rtf" lrecl = 32767;
file "c:\temp\want.rtf";
input;
length rtf $32767;
rtf = _infile_;
rtf = tranwrd(rtf, 'this value is superscripted 2', 'this value is superscripted \super 2 \nosupersub');
rtf = tranwrd(rtf, 'this value is subscripted 2', 'this value is subscripted \sub 2 \nosupersub');
put rtf;
run;
I don't believe this is possible in ODS LISTING. (Anyone who tells you you aren't using ODS is wrong, because listing is an ODS output destination just like all of the other destinations, but i'm assuming you mean you can't use anything other than ODS Listing, or use some of the common ODS tricks like ODS ESCAPECHAR).
However, ODS Listing doesn't have much available to it in terms of playing with fonts. You can put a super-2:
ods listing;
proc print data=sashelp.class;
title "Fun²";
run;
ods listing close;
by literally typing the character into your text, but that's not available for every possible superscript, and I don't think there are subscript equivalents in the listing font.
You can find a listing of characters online, for example in this paper. You can insert them with '##'x where ## is the 2 digit hex code for the character, or by typing them (alt+0178 for ² for example, or use character map to find them; make sure you use the right font.)

How to restore the default html output destination in SAS?

This must be so simple, but I can't find it:
How do you restore the default output destination in SAS 9.3?
Unlike 9.2, that is HTML.
In other words, which commands voids this statement.
ods html close;
You can turn HTML back on with
ODS HTML;
but there are probably other options you need...like a filename
ODS html file="My File.htm";
ODS HTML