/* SAS does a good job with crosstabs by using the TABLES command in PROC FREQ. However, if you want to get this stuff put into a SAS dataset, you got a little extra programming to do. This program creates a dataset that looks very similar to the printed output you get when you use PROC FREQ via the output window. Note that two options are needed in PROC FREQ command to make this happen - "outpct sparse". The SPARSE command tells SAS to print out cases where the counts or percentages are zero. Otherwise, when writing to a SAS dataset, they will be supressed. You will also need to use PROC TRANSPOSE to re-arrange the data. */ data mydata; input Y VAR1 VAR2 VAR3; cards; 1 10 33 4 0 20 21 3 1 30 59 2 1 20 76 1 0 20 24 3 0 . 30 2 1 10 28 2 1 10 49 2 0 30 76 4 1 20 59 2 ; %macro myfreq_table(var1,var2,type,mydata); /* var1=first variable in crosstab var2=second variable in crosstab type='count' =frequency counts in crosstab 'percent' =percent of total 'pct_row' =row percentages in crosstab 'pct_col' =column percentages in crosstab 'all' =include ALL the statistics mydata=your dataset name output name of dataset will be 'mytable_all' and 'mytable_(type)' */ OPTIONS NOTES SOURCE SOURCE2 MPRINT MLOGIC MERROR SYMBOLGEN; proc freq data=&mydata; tables &var1*&var2 /out=myout outpct sparse ; run; proc transpose data=myout out=mytable_all (drop=_label_); by &var1; var count percent pct_row pct_col; id &var2; run; %if %upcase(&type)^=ALL %then %do; data mytable_&type; set mytable_all; if _NAME_^=%upcase("&type") then delete; run; %end; %mend myfreq_table; %myfreq_table(y,var1,count,mydata);