BookmarkSubscribeRSS Feed
CurtisER
Obsidian | Level 7

Hello,

 

I was trying to find documentation that explains how to generate a plain text file using ODS LISTING using PROC REPORT.  I have successfully generated a PDF, RTF and tagsets.EXCELXP.  However, using ODS LISTING to generate a plain text file doesn't work and the headings, columns, pagination are all off.  Is there an easy way to produce a plain text file while still using the same PROC REPORT code for the report layout?  I've been googling and searching through SAS support but I can't seem to find any articles that discusses plain text using ODS and PROC REPORT.  (Note though, I wasn't asking for an HTML or HTML5 file -- just plain text file.)

 

Thanks in advance.

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Errm, what do you expect from a plain text file?  PDF, RTF, HTML etc. all have lots of extra information to tell the rendering program how to display the information given.  Plain text is, as per the name, plain ASCII, no frills at all.  You will not get pagination, borders, special characters.  Even the report layout maybe off as all the layout can deal with is either tab characters or spaces and tabs render differently on different apps.

So what do you need the plain text version for?  If its for reading back in then save as a data transport file - such as CSV.  

CurtisER
Obsidian | Level 7

Mostly to provide another option for section 508 compatibility.


@RW9 wrote:

So what do you need the plain text version for?  If its for reading back in then save as a data transport file - such as CSV.  


 

Reeza
Super User

It may be best for you to post an example where things don't line up how you'd like and perhaps someone can help with that?

 

As is, though, make sure to set the settings for a text file and generate the listing file.


This as a basic check works, but I don't know what's not working for you specifically, and I don't want to make up more proc reports this morning. My coffee has not kicked in yet.

 

option orientation=portrait leftmargin=0.5 rightmargin=0.5 topmargin=0.5 bottommargin=0.5;

ods listing file='C:\_localdata\sample.txt' ;


proc report data=sashelp.class nowd;
column name sex height weight;
define sex / width=10;
run;


ods listing close;
ballardw
Super User

If you have a Proc Report that has multiple pages in RTF or PDF then I would be very surprised if the pagination remained the same as there are is a lot more interaction in the LISTING destination between system options such as LineSize and PageSize. Also there are options in Proc Report specifically for listing appearance that would have no effect on ODS output such as LS, Panels, PS and Split.

 

Also you may want to be aware the FORMCHAR option becomes an issue depending on the font used to generate the report and the assumed font used by other plain text viewers. Also anyone using a non-monospaced font in their text viewer won't be happy with the appearance in general.

CurtisER
Obsidian | Level 7

I have 12 reports to generate in plain text format.  (I already have a set of 12 PDF, 12 RTF, and 12 XLS.)

 

Here's a working code that I was able to get a reasonable output:

 

   /* TABLE 1 TXT ******************************************************************************* */
   options nodate orientation = landscape pageno = 1
           topmargin = 0.4in bottommargin = 0.4in
           leftmargin = 0.4in rightmargin = 0.4in;

   ods listing close;
   ods escapechar = '^';

   title1 h=8pt j=l f='Courier New';

   footnote h=8pt j=l f='Courier New';

      proc report data = output_table_1 nowd ls = 155 list headskip headline style = monospace nocenter
                  style(report) = {fontfamily='Courier New' font_size = 8pt}
                  style(header) = {fontfamily='Courier New' font_size = 8pt}
                  style(column) = {fontfamily='Courier New' font_size = 8pt}
                  style(lines)  = {fontfamily='Courier New' font_size = 8pt};
         columns eof newtxttable
                 titlesp ("_Not seasonally adjusted_" sea_mov otmccnsa)
                         ("_Seasonally adjusted_" otmccS sig_chg);

         define eof / display noprint;
         define newtxttable / order noprint;
         define titlesp / "Industry /" display left format = $87. WIDTH = 71 STYLE(COLUMN) = {JUST = L ASIS = ON};
         define sea_mov / "/ Normal/seasonal/movements" format = 8.1 WIDTH = 15 STYLE(COLUMN) = {JUST = D};
         define otmccnsa / "Change from/&MMMYYpm. to/&MMMYYc." format = 8.1 WIDTH = 15 STYLE(COLUMN) = {JUST = D};
         define otmccS / "Change from/&MMMYYpm. to/&MMMYYc." format = $8. WIDTH = 13 STYLE(COLUMN) = {JUST = D};
         define sig_chg / "1-month/minimum/significant/change" format = 8.1 WIDTH = 13 STYLE(COLUMN) = {JUST = D};

         break after newtxttable / page;

         compute before _page_ / style = {just = LEFT fontfamily='Courier New' font_size = 8pt};
            line @1 "TABLE 1:  Employment: normal seasonal movements, over-the-month changes, and tests of significance (in thousands)";
            line " ";
         endcomp;

         compute after _page_ / style = {just = LEFT fontfamily='Courier New' font_size = 8pt};
            length text0 text1  text2  text3  text4  text5
                        otext1 otext2 otext3 otext4 otext5 $134.
                   len0 len1  len2  len3  len4  len5
                       olen1 olen2 olen3 olen4 olen5 8.;

            text1 = "* Passed test of significance. Significant over-the-month changes are calculated at a 90 percent confidence level. The standard error";
            len1  = 133;
            text2 = "is used for a 1-month change. Estimated over-the-month change passes test of significance if change is greater than minimum";
            len2  = 123;
            text3 = "significant change. The variance for total nonfarm is an approximation because government and rail transportation are not based on a";
            len3  = 132;
            text4 = "probability sample. Federal government and rail transportation are essentially full population counts and do not contribute to";
            len4  = 126;
            text5 = "variance. State and Local government variances were approximated by extrapolating from the variances for similar size industries.";
            len5  = 129;

            text0 = "See footnote at end of table.";
            len0  = 29;

            if (eof = 0) then do;
               otext1 = text0;
               olen1  = len0;
               otext2 = " ";
               olen2  = 0;
               otext3 = " ";
               olen3  = 0;
               otext4 = " ";
               olen4  = 0;
               otext5 = " ";
               olen5  = 0;
            end;
            else if (eof = 1) then do;
               otext1 = text1;
               olen1  = len1;
               otext2 = text2;
               olen2  = len2;
               otext3 = text3;
               olen3  = len3;
               otext4 = text4;
               olen4  = len4;
               otext5 = text5;
               olen5  = len5;
            end;

            line " ";
            line @1 otext1 $varying. olen1;
            line @1 otext2 $varying. olen2;
            line @1 otext3 $varying. olen3;
            line @1 otext4 $varying. olen4;
            line @1 otext5 $varying. olen5;
         endcomp;
      run;

   ods listing close;

   title;
   footnote;
/************************************************************************************* TABLE 1 */

 

Textual output - I had to fudge the number to 9999's and showing only 1 line of the output for illustration purpose:

 

TABLE 1:  Employment: normal seasonal movements, over-the-month changes, and tests of significance (in thousands)                                          
                                                                                                                                                           
                                                                           ____Not seasonally adjusted_____  ____Seasonally adjusted_____
                                                                                                                                  1-month
                                                                                    Normal      Change from  Change from          minimum
                                                                                  seasonal     Dec. 2016 to  Dec. 2016 to     significant
  Industry                                                                       movements        Jan. 2017  Jan. 2017             change
  ---------------------------------------------------------------------------------------------------------------------------------------
                                                                                                                                         
  Total nonfarm                                                                    -9999.0          -9999.0  999.0*                 999.0

This is the PDF output:

PDF Output

Reeza
Super User

The differences I see, underline/bold are things not available in plain text files anyways. 

 

If you are using plain text, you do manually have to customize everything. It does suck that the same code won't work on the different destinations but I also wouldn't have expected it to work. 

 

Wasn't there a recent announcement of enhancements to the accessibility options in SAS?

CurtisER
Obsidian | Level 7

Understood.  It's a bit of work and manipulating to put the headings, columns, and data into their respective places in a text file.

 

Do you or anyone know of any papers written about using plain text in an ODS destination?  I'm hoping for some tips and new tricks to generating plain text files without having to code one for each reports.  (crossing fingers)

 

Thanks!

Reeza
Super User

I'd probably wait for Cynthia or someone from SAS to comment but I think customizing text files would be in a lot of old papers on lexjansen.com. 

 

Good Luck.

 

What about a journal style with ODS RTF? Does that make it closer to what you might need?

ballardw
Super User

Here's a silly thought: Take the RTF and do a FILE - SAVE AS plain text and see if that works. Probably should start with a documented generated with style that uses all monospace font everywhere in the tables.

 

I have worked with generating plain-text file output but to have real control involved intimate acqaintance with summarizing the data first, getting things in the correct order and then becoming very familiar with the PUT statement and its options to control column/ line placement and the ancient overprint behavior to generate underlined text.

Cynthia_sas
SAS Super FREQ

Hi:

  I'm not sure what you expect to get. You have turned OFF the listing window. The example that was already posted by Reeza:


ods listing file='C:\_localdata\sample.txt' ;


proc report data=sashelp.class nowd;
column name sex height weight;
define sex / width=10;
run;


ods listing close;

Is the answer to your question. It's either the above code technique or using PROC PRINTTO.

 

Either way, you have things in your code  that don't make sense for LISTING output:

-- style=monospace seems to be ignored. Not sure why you even have it

-- your font specifications in the PROC REPORT statement will be ignored by ODS LISTING, which you have turned off and you don't show any other ODS statements, so I'm not sure why you even have this

-- style(column) respected by style-based ODS destinations, ignored by ODS LISTING (again, which you seem to have turned off)

-- COMPUTE ... /style= in your COMPUTE blocks again, respected by style-based ODS destination, ignored by ODS LISTING

-- LINE statements with @ placement will work in  LISTING, but probably not in style-based destinations as you want.

-- ODS ESCAPECHAR ... see the doc http://support.sas.com/documentation/cdl/en/odsug/69832/HTML/default/viewer.htm#p11xia2ltavr8ln17srq... specifically the Restrictions note that it is not used for ODS LISTING

 

  You said that your code was producing PDF output, and I can understand all your STYLE overrides working for PDF. However, you did NOT show what code was actually creating the LISTING-like output you produced. Do you have a PROC PRINTTO somewhere in your code?

 

cynthia

 

As an example of how different options are respected by different destinations:make_file_listing.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 9607 views
  • 0 likes
  • 5 in conversation