I have a data set like below , here Y is Yes and N means No
data have;
infile cards dlm='09'x;
input a$ b$;
cards;
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y N
Y N
Y N
Y N
Y N
Y N
Y N
;
run;
i have to create a summary like below for the counts of a and b
Row Labels | B No | B Yes | Grand Total |
A no | 10 | 10 | |
A Yes | 7 | 7 | 14 |
Grand Total | 7 | 17 | 24 |
the Numbers present in the want table is the count of Y and N of the Have dataset , the number present in each cell is determined like below :
Here A no and B No is if A and b couloumn both are N
A no B yes means column A is N and column B is Y
A yes B No means column A is Y and column B is N
A Yes B Yes means both column A and Column B is Y
PROC FREQ does that by default. You can add formats to your data to get it show up as N/Y.
proc format;
value demo_fmt
Y='Yes'
N='No'
Other='CheckMe';
run;
proc freq data=have;
table a*b;
format a b demo_fmt.;
run;
@soham_sas wrote:
I have a data set like below , here Y is Yes and N means No
data have;
infile cards dlm='09'x;
input a$ b$;
cards;
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y N
Y N
Y N
Y N
Y N
Y N
Y N
;
run;
i have to create a summary like below for the counts of a and b
Row Labels B No B Yes Grand Total A no 10 10 A Yes 7 7 14 Grand Total 7 17 24 the Numbers present in the want table is the count of Y and N of the Have dataset , the number present in each cell is determined like below :
Here A no and B No is if A and b couloumn both are N
A no B yes means column A is N and column B is Y
A yes B No means column A is Y and column B is N
A Yes B Yes means both column A and Column B is Y
It is best for PROC TABULATE.
data have;
input a $ b $;
cards;
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
N Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y Y
Y N
Y N
Y N
Y N
Y N
Y N
Y N
;
run;
proc tabulate data=have;
class a b;
table a all='Total',b all='Total';
keylabel n=' ';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: