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
| 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!
@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 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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.