The SAS Output Delivery System and reporting techniques

SPLIT FUNCTION NOT WORKING WITH ODS PDF

Reply
New Contributor
Posts: 3

SPLIT FUNCTION NOT WORKING WITH ODS PDF

Hi,

I'm using ODS to generate a PDF file. I would like to 'split' and print the data of a column based on a special character. For E.g., '*'. I'm using the below code.

SAS version : SAS 8.2

data final;
input factor category name $ name2 $;
cards;
2 34 abc*bac hgh*sgd
3 45 gcf*gdf ahd*has
;
run;

ods pdf file ="c:\tmp\sample_test.pdf" ;
     proc report data=final nocenter nowindows missing                                      
                  spacing=1 headline headskip split='*' ; 
columns factor category name name2;
define factor / "normal" order order=data width=10;
define category / "cat" width=13;
define name / display width=6 flow;
define name2 / display width=6 flow;
run;
ods pdf close;

The split option given in the proc report is working only in the report but not in the ODS PDF output. Any suggestions?

SAS Super FREQ
Posts: 8,740

SPLIT FUNCTION NOT WORKING WITH ODS PDF

Hi:

  Many of the techniques you show, including the * as a split character are LISTING only options. You will probably not be able to have 1 program that will work for LISTING and PDF. You will need to use ODS ESCAPECHAR to insert a carriage return or line feed into your data before using it with ODS PDF.

  Options like WIDTH, FLOW, HEADLINE, SPACING, etc are LISTING only options.

cynthia

New Contributor
Posts: 3

SPLIT FUNCTION NOT WORKING WITH ODS PDF

Hi Cynthia, Thanks alot for your response. I'm bit confused about the same. If possible, could you please provide a sample peice of code so that I will try from my end?

Actually, we are getting the data in a different format from external sources. (with a special character '^' inserted in between the data) . We need to split the data based on '^' and should generate a PDF.

For E.g;

Input data from External data sources
----------------------------------------------------

1 abc^bca   ght^ygs
2 gde^acb   age^adc

We want this to be printed in the output PDF as given below::

1 abc     ght
  bca     ygs

2 gde     ygs
  acb     adc

SAS Super FREQ
Posts: 8,740

Re: SPLIT FUNCTION NOT WORKING WITH ODS PDF

Hi:

  I have some code that illustrates the use of a newline character to split text in a cell. The way to do this with ODS is to use ODS ESCAPECHAR. In my code, I am reading in data and inserting the ESCAPECHAR controls into my data value.

  Since you already have data with a ^ (caret) as a special indicator of where a line feed should be inserted, then you would have to use functions like FIND, SUBSTR or TRANWRD to replace your ^ or * with the correct ESCAPECHAR function. As I said, the SPLIT character with PROC REPORT works in headers with ODS destinations, but within DATA cells, you would have to use ODS ESCAPECHAR functions to insert a line feed or new line character. The LISTING window or LISTING destination was the original way that output was created, so many procedures, like PROC REPORT and PROC TABULATE had some special options that were specific to how LISTING worked. Those same options generally do NOT work with ODS destinations like PDF, RTF and HTML that use proportional spaced fonts and style templates for styling the output. For example, the BOX option of PROC REPORT was originally created so PROC REPORT could have a box around the output like TABULATE, but that option is irrelevant in PDF, RTF or HTML, because each of those destinations puts the output in a table using destination-specific methods.

   If you are running SAS 9.1 or earlier, then you would need the original newline command, which was ESCAPECHAR+n:

ODS ESCAPECHAR='~';

and then change your data from: abc^bca to: abc ~n bca

If you are using SAS 9.2 or 9.3, then you would change your data to use the ESCAPECHAR {newline} function, from: abc^bca to: abc~{newline 1}bca

The code below produced the attached screenshot. To translate your data into a new text string, I think the TRANWRD function would work for you. Just be sure to make the new variables long enough to hold the data values and the inline formatting commands. Something like this (untested), assume your original variables are called STR1 and STR2:

  newstr91 = tranwrd(str1,'^',' ~n ');

  newstr92 = tranwrd(str2,'^',' ~{newline 1} ');

  Note that for the PDF destination, your code MUST use the same ESCAPECHAR (~) in the ODS ESCAPECHAR statement and in the program/data. Also, if you use the changed data with the LISTING destination, you will see the ~n or ~{newline 1} in the LISTING window. ODS ignores REPORT options like WIDTH=, SPACING=, HEADLINE, HEADSKIP, FLOW, etc. And, LISTING ignores ODS specific features such as ESCAPECHAR functions and STYLE overrides. So,

cynthia

data jabber;

length pline1 pline2 $100 lf_pline91 lf_pline92 $200;

infile datalines dlm=',' dsd;

input linenum pline1 $ pline2 $;

lf_pline91 = catx('~n',pline1, pline2);

lf_pline92 = catx('~{newline 1}',pline1,pline2);

return;

datalines;

1, "Twas brillig and the slithy toves","Did gyre and gimble in the wabe."

2, "All mimsy were the borogroves,","And the mome raths outgrabe."

;

run;

    

ods listing close;

options orientation=landscape topmargin=.5in bottommargin=.5in

        leftmargin=.5in rightmargin=.5in;

           

ods escapechar='~';

ods pdf file ="c:\temp\sample_test.pdf" ;

proc report data=jabber nowd split='*' ;

title 'Data Uses ODS ESCAPECHAR';

columns linenum pline1 pline2 lf_pline91 lf_pline92;

define linenum / "Number" order order=data;

define pline1 / display "Header*Uses*Split*Character";

define pline2 / display;

define lf_pline91 / display;

define lf_pline92 / display;

run;

ods pdf close;


use_newline_pdf.jpg
New Contributor
Posts: 3

SPLIT FUNCTION NOT WORKING WITH ODS PDF

Thanks a lot cynthia. I will try as per your suggestions and let you know the updates. Thanks once again for your timely help.

Occasional Contributor
Posts: 7

Re: SPLIT FUNCTION NOT WORKING WITH ODS PDF

Thanks, Cynthia

The code sample you give for splitting PDF text is of great help to me. I've save it and will try it later on generating PDF with ODS.

Best regards.

Ask a Question
Discussion stats
  • 5 replies
  • 2930 views
  • 0 likes
  • 3 in conversation