How can I assign a length to a column created by a tabulate statement?
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;
You can assign a format, I'm not sure about length.
n*var_x*f=8.1
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]
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.
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.
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;
I was fairly over thinking it. I just declared the length in the datastep after.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.