BookmarkSubscribeRSS Feed
aloou
Obsidian | Level 7

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:

tab1.PNG

Howevere, i want to get the output well organized as follows :

tab2.PNG

 

i will be so grateful for your help.

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @aloou 

Could you try to modify you TABLE statement as follows:

TABLE _CHARACTER_ * (PctN) / ROW = FLOAT ;

aloou
Obsidian | Level 7

Hello,

i have tried what you have proposed but as an output i keep getting the same as this:

tab1.PNG

ed_sas_member
Meteorite | Level 14

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.

 

ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 808 views
  • 0 likes
  • 3 in conversation