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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.