Hello everyone,
i am running a proc tabulate on a table as follows:
PROC TABULATE
DATA=la_rec.BIL_CTX_REF_HEBDO out=work.tabs ;
CLASS _CHARACTER_ / ORDER=UNFORMATTED MISSING;
TABLE _CHARACTER_,
N
PctN ;
;
RUN;
i get as a result i get an outpu as follows:
Howevere, i want to get the output well organized as follows :
i will be so grateful for your help.
Hi @aloou
Could you try to modify you TABLE statement as follows:
TABLE _CHARACTER_ * (N PctN) / ROW = FLOAT ;
Hello,
i have tried what you have proposed but as an output i keep getting the same as this:
Hi @aloou
I think you should add a preliminary step prior to proc tabulate in order to put all character variable values in the same variable, and then use this new variable as the class variable.
You will need to process the output data set created by proc tabulate.
Here is an example using data you should have available.
proc tabulate data=sashelp.class out=work.tab ; class _character_; table _character_ , n pctn; run; OPTIONS Missing=' '; data work.want; set work.tab (drop=_type_ _page_ _table_); newcol= cats(of _character_); run; options missing='.'; proc print data=work.want; var newcol n pctn_00; run;
Elements you need to pay attention to:
If you have missing CLASS variables that are numeric and want to use them and do not set OPTIONS MISSING=' '; then you will likely end up with . in the value of the newcol. The example shows only character but numeric class could be included. In which case you need to include the variable names in the CATS function.
You need to drop at least the _TYPE_ variable to use CATS(_CHARACTER_) because the _type_ is character. If you need to use the type, not unlikely at some point, then you will need to explicitly list the names of ALL of the variables you want to combine into a single column label.
If you use a tables statement with something like:
Tables classvar1*Classvar2
to create you row labels then you likely will want to use something like: Newcol = catx(' ',of _character_) or the list of variables to ensure that there is a space or desired separator between the columns of the row label values.
You could also change the name/label for the statistic variables requested. The example above uses Pctn_00 because you can get different PCTN statistics and the digits following the PCTN will relate to the different versions. In which case you will likely have to do something else to combine rows.
Also if you have PCTN and PCTSum in the same tabulate call or multiple TABLE statements you will likely have other manipulation issues involved.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.