1
votes

I have some data in SAS that I need to manipulate but I am having trouble with. My columns are

id#, age, and male

1 20 N

2 20 Y

3 21 Y

4 23 N

5 21 Y

6 21 N

7 20 N

8 21 Y

9 23 Y

Is there a way to get %male vs age? That is, age is the columns and for each column I want to know the percent male? I want to be able to use proc means and not proc tabulate to find this. Thanks.

2
Why do you say you do not want to use PROC TABULATE, which is the procedure made to do what you ask? That's rather like saying "Please tell me how to use a fork to eat this chicken broth. I want to use a fork and not a spoon. Thanks." - Joe

2 Answers

1
votes

That's not what PROC MEANS does, except in the special case of 1/0 fields. You could convert the Y and N to 1 and 0 and take the average of that new field, which would be equivalent to the percentage of males; however, with the data as is, PROC MEANS cannot give you the percentage in each category. That is what PROC FREQ or PROC TABULATE does.

0
votes
data input;
input id age male $;
cards;
1 20 N
2 20 Y
3 21 Y
4 23 N
5 21 Y
6 21 N
7 20 N
8 21 Y
9 23 Y
;
run;

ods trace on;
ods output CrossTabFreqs=work.stats;
proc freq data=input;
tables age*male;
run;

Your results:

options nolabel;
proc sql;
select age, RowPercent as MalePercent, 100 - RowPercent as WomanPercent
from work.stats
where _type_='11' and male='Y';
quit;

'11' is binary for "both age and male variables contributed to this summary observation".

In questions like this it's good to say whether you want just to "see" result or you want to store it in a table (maybe that's why PROC TABULATE was refused?).