BookmarkSubscribeRSS Feed
mp_C
Calcite | Level 5
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*
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
mp_C
Calcite | Level 5
Thanks, I found the solution with some help from my friends :))
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*;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 685 views
  • 0 likes
  • 2 in conversation