Help using Base SAS procedures

Hypenation of labels in proc tabular vs proc freq

Reply
New Contributor
Posts: 4

Hypenation of labels in proc tabular vs proc freq

[ Edited ]

Hi there!

I am using a format in a label in both proc freq and proc tabular for a variable of the same length (8.).

However, in proc tabular, in line breaks, a hyphen is added while in proc freq not.

The format is defined in the format statement as follows:

 

6=   'inter-  ven-    tionell:andere  lokale'

Here is the output of proc freq (which is what I want):

 

Inter-  |

ven-    |

tionellSmiley Indifferent

andere  |

lokale  |

 

and here of proc tabulate:

Inter-  |

ven-    |

tionell-|

:andere |

 lokale |

 

You can see that in proc tabulate, an extra hypen is inserted when splitting the text.

I am using SAS9.2 under linux. Output is plain listing.

 

How can I control this?

Thank's for your help!

Trusted Advisor
Posts: 1,115

Re: Hypenation of labels in proc tabular vs proc freq

Hi @Dondondon,

 

If you insert a blank after the colon in the format label, you will improve the chances that PROC TABULATE will break the line at the blank:

6=   'inter-  ven-    tionell: andere  lokale'

 

New Contributor
Posts: 4

Re: Hypenation of labels in proc tabular vs proc freq

Yes, this removes the hyphen, but the word in the next line is no longer left justified.
Trusted Advisor
Posts: 1,115

Re: Hypenation of labels in proc tabular vs proc freq

[ Edited ]

Strange. In my PROC TABULATE output it is left justified:

tabulate.PNG

 

Edit: (using SAS 9.4 under Windows)

Super User
Posts: 10,497

Re: Hypenation of labels in proc tabular vs proc freq

Post your entire proc tabulate code as options may affect behavior. Also the ods destination as the different destinations can and will have different behavior as well as the ODS style in effect.

New Contributor
Posts: 4

Re: Hypenation of labels in proc tabular vs proc freq

proc tabulate data=c61adn_asww Format=8. ;
  class name Behandlungsart;
  table name=' ', (behandlungsart=' ' ALL='Total')*N=' '/Box='n Gesamt';
run; 

Thank's for your reply!

This is my code, "Behandlungsart" is the variable in question.

I didn't use ODS at all. All output is generated with proc printto print=output.lst in batch mode, or the Display manager in interactive mode. There is no difference whether the batch or interactive mode is used.

New Contributor
Posts: 4

Re: Hypenation of labels in proc tabular vs proc freq

Here is a minimal working example and output:

proc format;
  value behand_az16_l8z
    5=   'inter-  ven-    tionell:andere'
    6=   'inter-  ven-    tionell:andere  lokale'
    7=   'inter-  ven-    tionell:ausschl.system.'
    ;
run;
data bla;

  format behandlungsart behand_az16_l8z.;
  do i=5 to 7;
    behandlungsart=i;
    name=1;
    output;
  end;
  drop i;
run; 

proc tabulate data=bla Format=8.;
  class behandlungsart;
  table behandlungsart=' '*N=' ';
run; 

proc freq data = bla order = internal;
  table
    name * Behandlungsart / nopercent nocol norow    ;
run;

Here the output:

                                                           The SAS System                           15:06 Monday, March 21, 2016   1

                                                    ----------------------------
                                                    |        |        |inter-  |
                                                    |        |inter-  |ven-    |
                                                    |inter-  |ven-    |tionell-|
                                                    |ven-    |tionell-|:aussch-|
                                                    |tionell-|:andere |l.syste-|
                                                    |:andere | lokale |   m.   |
                                                    |--------+--------+--------|
                                                    |       1|       1|       1|
                                                    ----------------------------
                                                           The SAS System                           15:06 Monday, March 21, 2016   2

                                                         The FREQ Procedure

                                                  Table of name by behandlungsart

                                            name      behandlungsart

                                            Frequency|inter-  |inter-  |inter-  |  Total
                                                     |ven-    |ven-    |ven-    |
                                                     |tionellSmiley IndifferenttionellSmiley IndifferenttionellSmiley Indifferent
                                                     |andere  |andere  |ausschl.|
                                                     |        |lokale  |system. |
                                            ---------+--------+--------+--------+
                                                   1 |      1 |      1 |      1 |      3
                                            ---------+--------+--------+--------+
                                            Total           1        1        1        3

Super User
Posts: 10,497

Re: Hypenation of labels in proc tabular vs proc freq

Technically you are using an ODS destination, called ODS LISTING, it just looks like text Smiley Happy

Tabulate for listing never had much in the control over the text in the headers and what little is there is aimed at ROW headers. There doesn't appear to be any option to not print the - when tabulate is splitting text. If I had to output this to text as you are and not happy with the appearance from tabulate I would summarize the data (possibly using tabulate with OUT=) and see if I could use Proc Print as there is an explict split= option and you could add an * or other chacter to the  Label text (since formats in Print are for values).

 

Or move over to Proc Report.

 

In a last resort I go back to ancient data_null and put statements to explicitly place everything on a page, but again using summarized data.

Trusted Advisor
Posts: 1,115

Re: Hypenation of labels in proc tabular vs proc freq

Thanks for providing the sample code.

 

It seems to me that the issue with left-alignment is restricted to column labels. But it can be solved by putting two (col. 1) or one (cols. 2 and 3) protected blanks to the end of the format labels. So, with this modification my first suggestion, to insert a blank after the colon, should work. At least it works with my SAS 9.4:

 

Code:

proc format;
  value behand_az16_l8z
    5=   'inter-   ven-     tionell: andere  '
    6=   'inter-   ven-     tionell: andere   lokale '
    7=   'inter-   ven-     tionell: ausschl. system. '
    ;
run;

Again, the blanks at the end of the labels are protected blanks, 'A0'x (typed as Alt+0160).

 

Result:

----------------------------
|        |inter-  |inter-  |
|inter-  |ven-    |ven-    |
|ven-    |tionell:|tionell:|
|tionell:|andere  |ausschl.|
|andere  |lokale  |system. |
|--------+--------+--------|
|       1|       1|       1|
----------------------------

 

 

Ask a Question
Discussion stats
  • 8 replies
  • 454 views
  • 0 likes
  • 3 in conversation