00339ffc7a3455be4781e2399f0b37ff.ppt
- Количество слайдов: 51
The Great Escape(char) Prepared by Louise Hadden Lead Programmer Analyst April 2010 Abt Associates Inc.
The Great Escapechar What will we see in this presentation? Basic syntax of ODS ESCAPECHAR in titles and footnotes ODS ESCAPECHAR with ODS text fields ODS ESCAPECHAR with SAS procedures New Capabilities in SAS V 9. 2
The Great Escapechar What is ODS ESCAPECHAR? Funny squiggly stuff like ^ or ~ in your data or SAS® code!
The Great Escapechar ODS ESCAPECHAR is a “code” used in a SAS® program that produces ODS output. It switches on inline formatting for specified elements of the output. The code and commands are not visible in ODS output, but the results are! As the name implies, ODS ESCAPECHAR is designed to be used in output designated for the Output Delivery System. The default SAS® listing destination is not able to translate the formatting commands.
The Great Escapechar What are some of the things you can do with ODS ESCAPECHAR?
The Great Escapechar • Modify text strings such as titles, footnotes, and ODS text fields. • Modify variable values through in-line style commands, proc format, and the data step. ODS ESCAPECHAR is a good way to put the finishing touches on your SAS reports and graphics, without needing to post-edit.
The Great Escapechar I’ll briefly demonstrate the use of ODS ESCAPECHAR in three different ODS destinations: RTF, PDF and HTML.
The Great Escapechar
The Great Escapechar Where can you use ODS ESCAPECHAR? In ODS output: in titles and footnotes, ODS text fields, SAS procedures, and the data step.
The Great Escapechar How do you use ODS ESCAPECHAR?
The Great Escapechar Open your ODS destination(s) Specify an ODS ESCAPECHAR Feed in data containing your ODS ESCAPECHAR OR specify in-line style commands using your ODS ESCAPECHAR Close your ODS destination(s)
The Great Escapechar Specify your ODS ESCAPECHAR: ODS ESCAPECHAR=‘^’; Examples of commonly used “ESCAPECHARs” are “^”, “~”, and “#”.
The Great Escapechar You want to use one that would not ordinarily be found in SAS® data or procedural commands. Mainframe users will want to be particularly careful in specifying ESCAPECHARs: for example, the “^” is problematic with some mainframe operating systems and software.
The Great Escapechar The defaults, *ESC* (version 9) and ‘ 03’x (version 8. 2), contain multiple keystrokes and are used less frequently (we programmers being a lazy [or efficient!] bunch. ) It is also possible to specify longer ESCAPECHARs if you want (but why would you? )
The Great Escapechar Feed in data containing your ODS ESCAPECHAR: column 1 Frequency Percent --------------------------------**The probability is 99% or more that your 1 25. 00 *The probability is 95% or more that your 1 25. 00 ^{style [fontsize=6 pt] ^{dagger}}The 1 25. 00 proc freq data=footer; tables column 1; run;
The Great Escapechar In general, the way to use ODS ESCAPECHAR in data or in commands is to specify the escapechar (in this case the ^) and then commands enclosed in curly brackets {}. These can be nested as seen above.
The Great Escapechar Daggers (a special ODS ESCAPECHAR function) appear in the ODS output of PROC FREQ.
Titles and Footnotes The most common usage of ODS ESCAPECHAR is in titles, footnotes and ODS text fields. These are some of the functions you can use.
Titles and Footnotes Text functions: Superscripts & Subscripts title 2 height=2 color=red '^{super SUPER }' color=blue 'COOL ' color=black '^{sub Title Special Functions (Super, Sub) in V 9. 1}';
Titles and Footnotes Text functions: Special Characters title 3 height=4 color=red '^{dagger} Title Special Functions (Dagger) in V 9. 1';
Titles and Footnotes Text functions: Pre-Image (Post. Images work the same) title 4 height=5 '^S={preimage="bonnietiny. jpg"}' "Title Pre-Image in V 9. 1";
Titles and Footnotes Text functions: Line Breaks title 5 height=2 'Show Line Break in V 9. 1 ^n. Here is an Extra Line ^n. Handy if you want to exceed the 10 title line limit!';
Titles and Footnotes Text functions: RTF Control String title 6 height=3 '^ul Feed in Underline Command in V 9. 1 (RTF Only) ^ul 0'; You can also do HTML control strings in the same fashion.
Titles and Footnotes
Titles and Footnotes Special functions: Pageof, thispage, lastpage title 1 'Page ^{thispage} of ^{lastpage} - for RTF & PDF'; title 4 height=4 color=blue '^{thispage} of ^{lastpage} Title thispage-lastpage in V 9. 1 - RTF and PDF Only';
Titles and Footnotes RTF destination PDF destination
ODS Text Fields The ODS text command within ODS statements in “Printer” destinations such as RTF and PDF allows the user to insert lines of text after titles and procedures at will – or without running any procedures at all! ods rtf text='{animtext 1 This is an example of inserting a text field. }'; Full Disclosure: animtext 1 -6 only works with RTF. But it is very cool! “Real” examples of using ODS text fields are coming up.
ODS Text Fields ods pdf text = '^S={font_size=18 pt just=c font_face=Klingon} This is Klingon'; ods pdf text = '^S={font_size=18 pt foreground=blue just=c font_face=Romulan} This is Romulan'; ods pdf text = '^S={font_size=18 pt font_weight=bold foreground=brown just=c font_face=Federation} This is Federation'; ods pdf text = '^S={font_size=18 pt foreground=green just=c font_face=trek} This is NOT Klingon or Romulan or Federation'; ods pdf text = '^S={font_size=18 pt foreground=purple font_style=italic just=c font_face=arial} This is boring Arial';
ODS Text Fields How cool is that?
Procedural Output columns fmtvar ('Main Partner^{super **}' ( ('Sex' count 1 colper 1) ('Unprotected Sex^{super****}' count 2 colper 2) ) ) ('Non-Main Partner^{super***}' ( ('Sex' count 3 colper 3) ('Unprotected Sex^{super****}' count 4 colper 4) ) ) count boldit; Superscript - RTF
Procedural Output columns fmtvar ('^S={background=lightblue}Aged 18 to 24' count_msm 1 colper_msm 1) ('Aged 25 to 34' count_dm 1 colper_dm 1). . . Background Color of Spanning Headers - RTF
Procedural Output The code on the next page demonstrates using ODS ESCAPECHAR and some special functions (dagger and sigma) in procedural output. Both data step and PROC FORMAT functionality are used. NOTE: as in the special page numbering functions described above, HTML output should have an HTML extension, and RTF output should have an RTF extension, for these special functions to work reliably.
Procedural Output Procedure: ods pdf file='dagger_v 91. pdf' style=styles. journal; ods rtf file='dagger_v 91. rtf' path=odsout style=styles. journal; ods html file='dagger_v 91. html' path=odsout style=styles. journal; ods escapechar='^'; proc print data=printit noobs; var oneunfmted one dagger doubledagger sigma; format one. ; title 1 color=red bcolor=black 'Test Special Functions V 9. 1'; run; ods _all_ close; Even though you are not specifying any commands with ODS ESCAPECHAR within the procedure, you MUST have the ods escapechar= command in order to print the embedded commands.
Procedural Output HTML
Procedural Output
Procedural Output
Procedural Output proc format; value xit 1="Green" 2="Red"; value xtoo 1="1 ^n Yes" /* ODS ESCAPECHAR N */ 2="2 ^n No"; value $ fit "1"-<"2"="Green" "2"-<"3"="Red"; run; data one; length feed $ 132; xit=1; xtoo=2; feed=cat("1 ", "^R/HTML'<BR/>' ^R/RTF'line'", " Yes"); /* ODS ESCAPECHAR R */ run; data two; length feed $ 132; xit=2; xtoo=1; feed=cat("2 ", "^R/HTML'<BR/>' ^R/RTF'line'", " No"); /* ODS ESCAPECHAR R */ run;
Procedural Output /* Note that the string defining the variable FEED includes a line feed for both PDF and RTF and a tab for HTML */ data printit; set one two; run; ods pdf file='style_format_v 91. pdf' style=styles. journal; ods rtf file='style_format_v 91. rtf' path=odsout style=styles. journal bodytitle; ods html file='style_format_v 91. html' path=odsout style=styles. journal; ods escapechar='^'; proc print data=printit label noobs; var xit / style={just=l foreground=xit. }; var xtoo; var feed / style={just=l foreground=$fit. }; format xtoo. ; title 1 ‘Line Feeds’; run; ods _all_ close;
Procedural Output RTF PDF HTML As can be seen, the variable FEED is shown both color-coded and with a line feed in the PDF and RTF destinations, and both color-coded and with a tab in the HTML destinations. The control strings embedded in the FEED variable do not print.
ODS ESCAPECHAR looks great! So, why wouldn’t you use ODS ESCAPECHAR? • In-line style commands take up a lot of room (both in terms of variable length if using a data step or PROC FORMAT and in terms of ODS file size. ) • And. . . Not all features are available for all ODS destinations. Where file size is a concern, PROC TEMPLATE is a better bet as the style commands only occur once in a style template but many times when specifying in-line styles. All in all though, ODS ESCAPECHAR is great!
Now Available in SAS Version 9. 2! Some added functionality of ODS ESCAPECHAR in V 9. 2 includes unicode characters and special text decoration (underline, strike-through, lineover, etc. ) There is also a greater capability for nesting style commands.
New Attractions in SAS® V 9. 2 UNICODE CHARACTERS
New Attractions in SAS® V 9. 2 UNICODE CHARACTERS smiley='^{style [fontsize=14 pt] ^{unicode 263 B} black smiley}'; label smiley='^{unicode 263 b} Smile, ^n Smile!‘; PDF destination
New Attractions in SAS® V 9. 2 UNICODE CHARACTERS RTF destination HTML destination
New Attractions in SAS® V 9. 2 TEXT DECORATION STYLE ATTRIBUTE RTF
New Attractions in SAS® V 9. 2 TEXT DECORATION STYLE ATTRIBUTE PDF
Coming Attractions in SAS® V 9. 2 TEXT DECORATION STYLE ATTRIBUTE HTML
The End is Near
Acknowledgements SUPPORT. SAS. COM – the samples, FAQs and human beings behind the scene are the greatest! Scott Huntley for his inspirational talk at SUGI 31 on the future of reporting in 9. 2, and his patient, helpful advice on the use of ODS PDF. Eric Gebhart, Vince Del. Gobbo and Chevell Parker for introducing me to in-line styles (or style overrides as Vince prefers) in HTML-based tagsets. Sandy Mc. Neill, Lauren Haworth and Ray Pass for introducing me to the use of inline styles in PROC TABULATE and PROC REPORT. Cynthia Zender for her wise counsel on the use of in-line style commands and ODS ESCAPECHAR. Wayne Hester for his generous help with my problems with the RTF destination, and for coming up with really cool additions to the RTF toolset. I couldn’t have done it without them! Please read their papers listed in “Recommended Reading” below, and/or attend any of their presentations.
Contact Information Your comments and questions are valued and encouraged. Contact the author at: Louise Hadden Abt Associates Inc. 55 Wheeler St. Cambridge, MA 02138 (617) 349 -2385 (work) (617) 349 -2675 (fax) Email: louise_hadden@abtassoc. com Sample code is available from the author upon request.
Highly Recommended Reading Del. Gobbo, Vince. “A Beginner’s Guide to Incorporating SAS® Output in Microsoft® Office Applications. ” Proceedings of the Twenty-Eighth Annual SAS® Users Group International Conference. April 2003. Del. Gobbo, Vince. “Creating AND Importing Multi-Sheet Excel Workbooks the Easy Way with SAS®. ” Proceedings of the Thirty-First Annual SAS® Users Group International Conference. March 2006. Gebhart, Eric. “The Beginners Guide to ODS MARKUP: Don’t Panic. ” Proceedings of the Thirty-First Annual SAS® Users Group International Conference. March 2006. Hester, Wayne. “Teaching your RTF Tagset to Do Clever Tricks. ” Proceedings of the Thirty-First Annual SAS® Users Group International Conference. March 2006. Huntley, Scott. “Let the ODS Printer Statement Take Your Output into the Twenty-First Century. ” Proceedings of the Thirty-First Annual SAS® Users Group International Conference. March 2006. Parker, Chevell. “Generating Custom Excel Spreadsheets using ODS. ” Proceedings of the Twenty-Eighth Annual SAS® Users Group International Conference. April 2003. Pass, Ray and Mc. Neill, Sandy. “PROC REPORT: Doin’ It in Style!” Proceedings of the Twenty-Eighth Annual SAS® Users Group International Conference. April 2003. Pass, Ray and Mc. Neill, Sandy. “PROC TABULATE: Doin’ It in Style!” Proceedings of the Twenty-Ninth Annual SAS® Users Group International Conference. May 2004. Zender, Cynthia. “Funny ^Stuff~ in My Code: Using ODS ESCAPECHAR. ” Proceedings of SAS Global Forum 2007 Conference. April 2007.
00339ffc7a3455be4781e2399f0b37ff.ppt