BookmarkSubscribeRSS Feed
soham_sas
Quartz | Level 8

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 LabelsB NoB YesGrand Total
A no 1010
A Yes7714
Grand Total71724

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

2 REPLIES 2
Reeza
Super User

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


 

Ksharp
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 693 views
  • 1 like
  • 3 in conversation