The SAS Output Delivery System and reporting techniques

two-way frequency analysis

Reply
New Contributor
Posts: 2

two-way frequency analysis

Hi,

I need to get a table for gender by year for a specific range of years (2002-2007). I'm new to this program and as much as I understand I should first create a sub-set of years at question and then format my variables for the proc freq statement.

What I am getting so far - 0 ovservations from the data set.

data m.gender1;
set m.gender;
if gender=1 then gender1='F';
if gender=2 then gender1='M';
run; *it works*;

data m.gender_year;
set Tmp1.gender1;
year=datepart(created_date);
format year date9.;
run;

data m.year;
set m.gender_year;
where year=2002;
run; *0 observations*

proc freq data=m.gender_year;
Tables Year Gender1
Year*Gender1;
where year>=2002;
run; *doesn't work as well*
Super Contributor
Super Contributor
Posts: 3,174

Re: two-way frequency analysis

You have a libref of "Tmp1", first introduced in the second DATA step. Maybe that should be "m.gender1"?? Not sure.

My recommendation is to remove the WHERE filter and analyze your data in its entirety, using FREQ, first with no TABLES statement

Scott Barry
SBBWorks, Inc.
New Contributor
Posts: 2

Re: two-way frequency analysis

Thanks, I found the solution with some help from my friends Smiley Happy)
I did it this way:

data m.gender;
set cesgrdb2.Eben_out_vw (keep= created_date gender);
gender1=put(gender,1.); /*we specify the format and length of a new variable*/
run;

data m.gender1;
set m.gender;
if gender=1 then gender1='F';
if gender=2 then gender1='M';
run; *it works*;
data m.gender_year;
set Tmp1.gender1;
year=datepart(created_date);
format year date9.;
run;
data m.gender_year1;
set m.gender_year;
date=year(year);
run; */to get year in the table*/;

proc freq data=m.gender_year1;
Tables Date Gender1 /*it would be better to get a table the other way - Gender1*Date*/
Date*Gender1;
where date>=2002 and date<=2007;
run;*it works*;
Ask a Question
Discussion stats
  • 2 replies
  • 125 views
  • 0 likes
  • 2 in conversation