Hi,
I would like to create a table from the following data:
data have;
length Income $ 10;
input ID Income $ Pension;
cards;
1 400-500 .
2 300-400 1
3 500- 1
4 200-300 .
5 300-400 .
6 400-500 1
7 300-400 1
8 200-300 .
9 100-200 .
10 500- 1
;
run;
The data i this example concist of 10 individuals belonging to different income groups where som of them have pension payments (Pension=1) and some does not (Pension=.).
I have to create a table with proc tabulate that shows (1) the number of people in each income group, (2) the number of people with pension payments in each income group and (3) the percentege of people with pension payments of the total population in each income group.
The following syntax output the answer for the first two questions. I need help with the one regarding the percentege of people with pension payments of the total population in each income group.
proc tabulate data=Have format=comma12. ;
class Income ;
var ID Pension ;
table Income='' All='Total',
ID='Total population'*N=''
Pension='People with pensions' *sum=''
/box='Income group';
run;
Thanks!
Perhaps this will get you started:
data have; length Income $ 10; input ID Income $ Pension; cards; 1 400-500 0 2 300-400 1 3 500- 1 4 200-300 0 5 300-400 0 6 400-500 1 7 300-400 1 8 200-300 0 9 100-200 0 10 500- 1 ; run; proc tabulate data=Have format=comma12. ; class Income ; var ID Pension ; table Income='' All='Total', ID='Total population'*N='' Pension='People with pensions' * (sum='Count' mean="%"*f=percent8.) /box='Income group'; run;
Mean of 0/1 coded variable is the percent of "1" values. Either use a percentw. format as shown or if you dislike the % signs then a custom format with the MULT option can show a "nice" percentage value such as 66.7 instead of .666666.
Thank you so much! I will test it on Monday when I will have access to SAS!
Hope this should solve your problem:
proc format;
picture pct (round) low-high='009.99%';
run;
proc tabulate data=Have format=comma12.;
class Income;
var ID Pension;
table Income='' All='Total',
ID='Total population'*N=''
pension='People with pensions' *sum=''
pension*ROWPCTN<ID>*f=pct.
/box='Income group';
run;
Thank you so much! I will test it on Monday when I will have access to SAS!
Thanks again! your soution worked well!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.