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
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
Wanted to avoid proc freq. Is there a way to do this via proc tabulate?
@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.
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
Do you want a SAS data set or a report?
Sas data set
Is this a summation thing? Seems like a simple transpose?
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.