Help using Base SAS procedures

pulling out specific dates of a dataset for 3 years for each employee

Reply
Occasional Contributor
Posts: 10

pulling out specific dates of a dataset for 3 years for each employee

Hello,

I'm new to programing and am having lots o' troubles. I'd appreciate any help. I have a dataset that has a daily observation for 3 years, 2007, 2008 and 2009 for each armyid. They have a grade, rank and pay, which change over the years.
I need to GET RID of all dates except for /12/31/2007, 12/31/2008 and 12/31/2009, so essentially, if someone was in for all three years, they would have 3 obs for their armyid.

Before I can analyze average pay by rank, rank & gender, rank & race, (proc freq or proc means?) I first have to get rid of all the other observations. I've tried the code below, but i don't get all 3 observations for some of the armyids.


**getting only dec31 info into a dataset;

proc sort data=allinfo; by armyid date;

data yrend; set allinfo;
array dates {3} date01-date03;
if _n_ eq 1 then do;
date01='31dec07'd;
date02='31dec08'd;
date03='31dec09'd;
end;

do i=1 to 3;
cendate=dates{i};
if date eq cendate
then output;
end;

retain date01-date03;
format todate date cendate date9.;
drop date01-date03;
run;
end;
PROC Star
Posts: 7,467

Re: pulling out specific dates of a dataset for 3 years for each employee

Your code is more complicated than it has to be, but it will work. If you aren't getting all three records then I would guess that you don't have all three records for each army id.

You get a warning because you include a variable in your format statement called todate that you never use and, after the program has run, you get an error because of your last line (i.e., an end statement after the run statement). Just delete that last line (i.e., endSmiley Wink and you won't get the error.

HTH,
Art
> Hello,
>
> I'm new to programing and am having lots o' troubles.
> I'd appreciate any help. I have a dataset that has
> a daily observation for 3 years, 2007, 2008 and 2009
> for each armyid. They have a grade, rank and pay,
> which change over the years.
> need to GET RID of all dates except for /12/31/2007,
> 12/31/2008 and 12/31/2009, so essentially, if
> someone was in for all three years, they would have
> 3 obs for their armyid.
>
> Before I can analyze average pay by rank, rank &
> gender, rank & race, (proc freq or proc means?) I
> first have to get rid of all the other observations.
> I've tried the code below, but i don't get all 3
> observations for some of the armyids.
>
>
> **getting only dec31 info into a dataset;
>
> roc sort data=allinfo; by armyid date;
>
> data yrend; set allinfo;
> array dates {3} date01-date03;
> if _n_ eq 1 then do;
> date01='31dec07'd;
> ate02='31dec08'd;
> date03='31dec09'd;
>
>
> cendate=dates{i};
> te eq cendate
> then output;
> d;
>
> retain date01-date03;
> format todate date cendate date9.;
> drop date01-date03;
>
> end;
Super Contributor
Posts: 578

Re: pulling out specific dates of a dataset for 3 years for each employee

How about this?

data yrend; set allinfo;
if date in ('31dec07'd, '31dec08'd, '31dec09'd);
run;
Ask a Question
Discussion stats
  • 2 replies
  • 134 views
  • 0 likes
  • 3 in conversation