BookmarkSubscribeRSS Feed
Abz_17
Calcite | Level 5

Hi I have a data set which i would like to cross tabulate. My data currently looks like this

aborh                day         conversion

Unknown             1              219

A+                       1              445

A-                        1              137

AB+                    1              30

AB-                     1              14

B+                      1              133

B-                       1              61

O+                     1              602

O-                      1              236

Unknown           2              522

A+                     2              1411

A-                      2              426

AB+                  2              78

AB-                   2              27

B+                    2              356

B-                     2              135

O+                   2              1955

O-                    2              863

 

and I want it to look like this

 

                                 1             2

Unknown                219         522

A+                          445         1411

A-                           137         426

AB+                        30           78

AB-                         14           27

B+                           133         356

B-                            61           135

O+                          602         1955

O-                           236         863

 

Can someone please advise me as to how to get the cross tab above?

 

Thanks

9 REPLIES 9
PaigeMiller
Diamond | Level 26

PROC FREQ

 

See the example here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/procstat/procstat_freq_examples01.htm Your problem is essentially the same as the one shown for Eye Color and Hair Color

--
Paige Miller
Abz_17
Calcite | Level 5

Wanted to avoid proc freq. Is there a way to do this via proc tabulate?

PaigeMiller
Diamond | Level 26

@Abz_17 wrote:

Wanted to avoid proc freq.


Since you didn't give a reason, all I can say is that this is not a good position to take. PROC FREQ gives you exactly what you asked for. 

--
Paige Miller
Reeza
Super User

Your requirements are contradictory, if you want a data set proc tabulate is not the right approach, proc transpose is (solution shown by @PeterClemmensen). 

 

Wanted to avoid proc freq. Is there a way to do this via proc tabulate?

 

 

Sas data set

PeterClemmensen
Tourmaline | Level 20

Do you want a SAS data set or a report?

Abz_17
Calcite | Level 5

Sas data set

PeterClemmensen
Tourmaline | Level 20

Is this a summation thing? Seems like a simple transpose?

PeterClemmensen
Tourmaline | Level 20
data have;
input aborh $ day conversion;
datalines;
Unknown 1 219  
A+      1 445  
A-      1 137  
AB+     1 30   
AB-     1 14   
B+      1 133  
B-      1 61   
O+      1 602  
O-      1 236  
Unknown 2 522  
A+      2 1411 
A-      2 426  
AB+     2 78   
AB-     2 27   
B+      2 356  
B-      2 135  
O+      2 1955 
O-      2 863  
;

proc sort data = have;
   by aborh;
run;

proc transpose data=have out=want(drop=_name_) prefix=_;
    by aborh;
    id day;
    var conversion;
run;
D_Dunlap
SAS Employee

Hello,

If you want a report, you can try PROC TABULATE:

 

proc tabulate data=work.have format=8.0;
var conversion;
class aborh day ;


/* The TABLE statement defines the structure of your report */
/* TABLE PAGE,ROW,COLUMN; */

 

TABLE aborh,day={label=""}*conversion={label=""}*Sum={label=""} ;


/* Page Dimension - The above TABLE statement does not have */
/* a PAGE dimension */

 

/* Row Dimension -BELOW*/
/* aborh*/

 

/* Column Dimension - BELOW */
/* day={label=""}*conversion={label=""}*Sum={label=""} */

run;

 

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
  • 9 replies
  • 618 views
  • 1 like
  • 5 in conversation