BookmarkSubscribeRSS Feed
lgtea57
Calcite | Level 5
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;
2 REPLIES 2
art297
Opal | Level 21
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., end;) 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;
DBailey
Lapis Lazuli | Level 10
How about this?

data yrend; set allinfo;
if date in ('31dec07'd, '31dec08'd, '31dec09'd);
run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 693 views
  • 0 likes
  • 3 in conversation