BookmarkSubscribeRSS Feed
Dondondon
Calcite | Level 5

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

tionell:|

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!

8 REPLIES 8
FreelanceReinh
Jade | Level 19

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'

 

Dondondon
Calcite | Level 5
Yes, this removes the hyphen, but the word in the next line is no longer left justified.
FreelanceReinh
Jade | Level 19

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

tabulate.PNG

 

Edit: (using SAS 9.4 under Windows)

 

[Edit 2019-04-30: Reattached screenshot, which had been deleted by mistake.]

ballardw
Super User

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.

Dondondon
Calcite | Level 5
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.

Dondondon
Calcite | Level 5

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-    |
                                                     |tionell:|tionell:|tionell:|
                                                     |andere  |andere  |ausschl.|
                                                     |        |lokale  |system. |
                                            ---------+--------+--------+--------+
                                                   1 |      1 |      1 |      1 |      3
                                            ---------+--------+--------+--------+
                                            Total           1        1        1        3

ballardw
Super User

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

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.

FreelanceReinh
Jade | Level 19

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1202 views
  • 0 likes
  • 3 in conversation