DATA Step, Macro, Functions and more

Tabulate Length

Accepted Solution Solved
Reply
Super Contributor
Posts: 477
Accepted Solution

Tabulate Length

How can I assign a length to a column created by a tabulate statement?


Accepted Solutions
Solution
‎03-10-2016 09:44 AM
Super User
Posts: 17,750

Re: Tabulate Length

If you assign the length before the SET statement, I believe it changes it in the data step.

 

Then you can modify it as necessary within the proc.

data want;
length var $60.;
set tabulate_out;

*blah blah blah;

run;

View solution in original post


All Replies
Super User
Posts: 17,750

Re: Tabulate Length

You can assign a format, I'm not sure about length.

 

n*var_x*f=8.1
Super User
Posts: 10,466

Re: Tabulate Length

[ Edited ]

By Length I am assuming you mean the width of the column displayed. If you mean number of rows, which would be another way of thinking of "length" for a column, I haven't found anything other than severe data manipulation or obnoxious macro coding.

 

It depends to some extent on what type of column it represents.

If the variable is a Class variable then use a Classlev statement: Classlev Variablename/ style=[width=1in]; Note there are a number of units you can use, this is to create a one inch wide column. If the variable is stacked then the first (top) variable will control. Example:

Table variable1 variable2, someothervariable * n;

The width assigned to variable1 will usually control the width of the row header column.

You can set a table wide default on the tabulate statement with the stype option.

Sometimes I have had success with a width on a var statement as well: Var analysisvar / style=[width=.5in] but inconsistent depending on how I use that variable.

You can specify a width for a specific statistic as well.

Table variable1 variable2, someothervariable * n*{style=[width=.7in]

Super Contributor
Posts: 477

Re: Tabulate Length

I’m running into a scenario where I am outputting the contents of a tabulate.  One of the columns has a length of one when I output it.  But I want it to have a length of 60 when I use a datastep.

Super User
Posts: 10,466

Re: Tabulate Length

Time to provide some example data and the code you are currently using. Also the ODS destination involved. So much could be done in a datastep that details are needed. And Proc Print does allow per variable style overrides to set column widths if that might be helpful.

Solution
‎03-10-2016 09:44 AM
Super User
Posts: 17,750

Re: Tabulate Length

If you assign the length before the SET statement, I believe it changes it in the data step.

 

Then you can modify it as necessary within the proc.

data want;
length var $60.;
set tabulate_out;

*blah blah blah;

run;
Super Contributor
Posts: 477

Re: Tabulate Length

I was fairly over thinking it.  I just declared the length in the datastep after.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 300 views
  • 1 like
  • 3 in conversation