BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Akter
Obsidian | Level 7

Hi All, I'm struggling to generate the below output table "Output" from the below made dataset 'Have'. Your help will be highly appreciated. Cat, Dog and Birds are multiple response variable for each Subject ID. Want to generate output table as below  output table (Response Category by Total and Sex). 

Data Have;

Id     Cat   Dog   Bird   SEX
01     1       0       1         M
02     0       1       1         F
03     1       1       0         M
04     0       1       1         F
05     1       0       0         M 

 

Output table: 
Response Total Male Female
N n % N n % N n %
Cat 5 4 80% 3 3 100% 2 0 0
Dog 5 3 60% 3 1 33.30% 2 2 100
Bird 5 3 60% 3 1 33.30% 2 2 100

N=Total Obs (0 and 1), n=# of 1 (one)

Really appreciate your help!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Akter wrote:

Hi All, I'm struggling to generate the below output table "Output" from the below made dataset 'Have'. Your help will be highly appreciated. Cat, Dog and Birds are multiple response variable for each Subject ID. Want to generate output table as below  output table (Response Category by Total and Sex). 

Data Have;

Id     Cat   Dog   Bird   SEX
01     1       0       1         M
02     0       1       1         F
03     1       1       0         M
04     0       1       1         F
05     1       0       0         M 

 

Output table: 
Response Total Male Female
N n % N n % N n %
Cat 5 4 80% 3 3 100% 2 0 0
Dog 5 3 60% 3 1 33.30% 2 2 100
Bird 5 3 60% 3 1 33.30% 2 2 100

N=Total Obs (0 and 1), n=# of 1 (one)

Really appreciate your help!


This should get you started:

Data Have;
input Id $     Cat   Dog   Bird   SEX $ ;
datalines;
01     1       0       1         M
02     0       1       1         F
03     1       1       0         M
04     0       1       1         F
05     1       0       0         M 
;

proc tabulate data=have;
   class sex;
   var cat dog bird;
   table cat dog bird,
         (all='Total' Sex=' ')*(n='N' sum='n'*f=best5. mean='%'*f=percent7.)
         /box='Response'
         ;
run;

Default behavior for order of class variables means the F comes before M. A custom format could be used to create text of Female and Male from values of F and M.

The ='xxx' after a statistic or variable is an override of the default label. Sum of 1/0 coded numeric is the number of 1 and mean is the percent of 1 values. The *f= is used to assign a format to the statistic value. Default would typically be 2 decimals, which wouldn't make the mean look much like a percentage.

View solution in original post

2 REPLIES 2
ballardw
Super User

@Akter wrote:

Hi All, I'm struggling to generate the below output table "Output" from the below made dataset 'Have'. Your help will be highly appreciated. Cat, Dog and Birds are multiple response variable for each Subject ID. Want to generate output table as below  output table (Response Category by Total and Sex). 

Data Have;

Id     Cat   Dog   Bird   SEX
01     1       0       1         M
02     0       1       1         F
03     1       1       0         M
04     0       1       1         F
05     1       0       0         M 

 

Output table: 
Response Total Male Female
N n % N n % N n %
Cat 5 4 80% 3 3 100% 2 0 0
Dog 5 3 60% 3 1 33.30% 2 2 100
Bird 5 3 60% 3 1 33.30% 2 2 100

N=Total Obs (0 and 1), n=# of 1 (one)

Really appreciate your help!


This should get you started:

Data Have;
input Id $     Cat   Dog   Bird   SEX $ ;
datalines;
01     1       0       1         M
02     0       1       1         F
03     1       1       0         M
04     0       1       1         F
05     1       0       0         M 
;

proc tabulate data=have;
   class sex;
   var cat dog bird;
   table cat dog bird,
         (all='Total' Sex=' ')*(n='N' sum='n'*f=best5. mean='%'*f=percent7.)
         /box='Response'
         ;
run;

Default behavior for order of class variables means the F comes before M. A custom format could be used to create text of Female and Male from values of F and M.

The ='xxx' after a statistic or variable is an override of the default label. Sum of 1/0 coded numeric is the number of 1 and mean is the percent of 1 values. The *f= is used to assign a format to the statistic value. Default would typically be 2 decimals, which wouldn't make the mean look much like a percentage.

Akter
Obsidian | Level 7
Thank you so much for your help! I really appreciate your help!

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 557 views
  • 2 likes
  • 2 in conversation