Print superscript or subscript in SAS without ODS - sas

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.)

Related

SAS, change font size in the put statement

data _NULL_;
file print;
if e then put 'No observations';
set TableA end=e;
put 'here is the table A';
stop;
run;
How do I change font size and color for the quotes in the put statement?
In general you might want to use graphics options on a title statement.
However, ODS output can be modified with inline styling directives introduced via the escapechar.
ods pdf file='want.pdf';
ods escapechar = '^';
* standard options for title statement;
title color=white bcolor=blue bold italic height=36pt "Title for want";
data _null_;
file print;
put '^{style [fontsize=24pt color=Red]Hi}'; * inline styling;
run;
ods pdf close;

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;

SAS- Supress Results view on some, but not all, proc print ods outputs

I want to be able to print all of my reports to external files but only display a select few in the results viewer. In the below example I want reportA and reportB to be displayed AND printed (file.xls) but reportC to be printed to a separate file (file2.csv) and not displayed in the results viewer. Any ideas?
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
ods csvall file="/file/file2.csv";
proc print data=reportC;
run;
ods csvall close;
You can also use ODS EXCLUDE and ODS SELECT to target specific destinations.
For example, ods html select none; will turn off the HTML destination temporarily, but not actually close it - it just won't get any results for a while. You can then use ods html select all; to turn it back on.
You can also use ods html exclude all; to do the same thing and then turn it back on with ods html exclude none;.
With either statement, you can also use a where statement in the ods select/exclude to filter to only affect one specific part of an output. See the documentation for more details.
Close the list output which is the default. OR the HTML if that is the default results window in your system. Re-open the output after the file is created.
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
ods listing close;
ods html close;
ods csvall file="/file/file2.csv";
proc print data=reportC;
run;
ods csvall close;
ods listing;
ods html;
I actually found a better solution through using the proc export feature for suppressing display of the csv output.
ods msoffice2k file="/file/file.xls";
proc print data=reportA;
run;
proc print data=reportB
run;
ods msoffice2k close;
proc export data=reportC
outfile="/file/file2.csv"
dbms=dlm
replace;
delimiter=",";
run;
Thanks for the help #Reeza I'll keep those settings in mind for future projects.

Suppressing HTML output in SAS

I'm trying to suppress HTML output and get PROC PRINT to output only to CSV, but ODS HTML Close doesn't seem to work.
My code is:
ODS HTML close;
ODS CSV file="\\..output folder..\filename.csv";
proc print data=test;
run;
ODS CSV close;
ODS HTML;
Your approach seems a bit odd, why resort to ods csv?
SAS has a proc export procedure:
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace;
run;
You can further configure it to have a different delimiter, no headers etc.: http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000393174.htm
EDIT
In reply to your comment: i see two ways around the issues that keep you from trying proc export.
The first approach is setting the validvarname to ANY, which gives you great liberty in choosing variable names. E.g.:
options validvarname=ANY;
data test;
'Column Header Text I Want'n=1; output;
'Column Header Text I Want'n=5; output;
run;
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace;
run;
Personally, i'm not a fan of the above approach, since i find that it leads to harder-to-read code when you no longer have some naming rules for variables.
A second approach - which i prefer - is to label the variable with the text you want it to have and put the label option on your proc export. E.g.:
data test;
label variable_name='Column Header Text I want';
variable_name=1; output;
variable_name=5; output;
run;
proc export data=test outfile="\\..output folder..\filename.csv" dbms=CSV replace LABEL;
run;
Note that there is a small distinction in the output: the first approach will not put quotes around your column names while the second approach will do that.
Finally, while doing some extra reading myself, i stumbled across this, which may be of help to you as well: http://www.sascommunity.org/wiki/Create_a_CSV_file_without_column_names/headers_in_row_1#DATA_NULL_with_a_PUT_statement.2C_all_fields_quoted
I'm been trying all day and finally got it for me. What I wanted suppress from the results viewer is just below here (and the end of a macro). The results I wanted in the results viewer and now called in a separate macro at the end...
Brubumski
ODS HTML close; * bsk;
ods results off; * bsk;
ods csvall file="&file1";
proc print data=tr_outds noobs; run;
ods csvall close; * bsk;
ods results on; * bsk;
ODS HTML; * bsk;
%OdsOn1(outds,outds2,tr_outds, file1, file2); * bsk;
%mend process_input_data_10_10;
%macro OdsOn1(outds,outds2,tr_outds, file1, file2);
proc freq data=outds;tables Group_nm/missing;run;
proc freq data=outds2;tables case_id/missing;run;
proc print data=tr_outds(obs=10) noobs; run;* bsk;
ods csvall file="&file2";
proc print data=cases noobs; run;
ods csvall close;
%mend OdsOn1;
Ah, I've found out the problem. The results window will still display HTML output which will really slow the program down as ODS HTML CLOSE seems to only affect ouput to a specific file, not the results window.
In order to stop that, I should have used ODS RESULTS OFF; instead.
ODS RESULTS OFF;
ODS CSV file="\\..output folder..\filename.csv";
proc print data=test;
run;
ODS CSV close;
EDIT: It seems that ODS RESULTS cannot be turned on and off at will to cause only certain PROC PRINT statements to generate outputs. This is really annoying for me, so I'm going with Shorack's PROC EXPORT methods.