Contributor
Posts: 43

need help regarding counting N with respect to categorical

Hi,
I will be greatful if any one can help me to break the problem
I have a dataset with following variables
gender agegroup paper1 paper2 web1 web2 .........................
1 1 1 0 0 1
2 3 0 0 1 1
1 2 1 1 1 0
2 3 1 1 0 1

gender 1=male,2=female
age group 1=18-24, 2=25-30 3=31-35

i would like to find
gender wise age group wise how many people read at least any of two

Can any one can suggest the best way to find, please see my code
Thanks & Regards,
Suresh

here is my code tried with Proc Freq and Proc Tabulate :
PROC FREQ DATA=WORK.test
ORDER=INTERNAL
;
TABLES gender / NOPERCENT NOCUM SCORES=TABLE;
TABLES agegroup / NOPERCENT NOCUM SCORES=TABLE;
BY paper1 paper2 web1 web2
RUN;

CODE 2 WITH PROC TABULATE :
PROC TABULATE
DATA=work.test1

;
CLASS gender / ORDER=UNFORMATTED MISSING;
CLASS agegroup / ORDER=UNFORMATTED MISSING;
CLASS paper1 / ORDER=UNFORMATTED MISSING;
CLASS paper2 / ORDER=UNFORMATTED MISSING;
CLASS web1 / ORDER=UNFORMATTED MISSING;
CLASS web2 / ORDER=UNFORMATTED MISSING;
TABLE /* Row Dimension */
paper1
paper2
web1
web2

/* Column Dimension */
gender*
agegroup*
N ;
;

RUN;
Posts: 2,125

Re: need help regarding counting N with respect to categorical

Because the data are in one row per person, you can get it with a FREQ TABLE statement like

TABLES paper1*paper2;
BY gender agegroup;

then you just add up all the cells other than the 0-0 one for each age and sex category.

With a DATA step, you could get at it more directly;

DATA new;
SET old;
AnyPaper = paper1*paper2;
RUN;

PROC FREQ DATA=new;
TABLES gender*agegroup*anypaper;
RUN;
Discussion stats