BookmarkSubscribeRSS Feed
Solph
Pyrite | Level 9

I've a dataset with a variable death_year for year of death (2017 or before), and a bunch service use year variables (1 or 0 as yes or no) between 2010 and 2018 (service2010, service2011, service2012, .... service2018). I want to identify # of service use two years after death year to validate the value of death year.

 

num_use_post_death=sum(of serviceXXXX - service2017);
where XXXX is the individual person's value of death_year +2.

 

Thanks.

4 REPLIES 4
gamotte
Rhodochrosite | Level 12

Hello,

 

It would be easier to answer if you post have and want datasets in the form of datasteps.

 

data want;
    set have;
    array services(*) service2010-service2018;

    startindex=death_year-2009;
    stopindex=dim(services);

    do i=startindex to stopindex;
        num_use_post_death=sum(num_use_post_death,services(i));
    end;
run;
PGStats
Opal | Level 21

Like @gamotte, but specifying explicit array bounds:

 

data want;
set have;
array services{2010:2018} service2010-service2018;
num_use_post_death = 0;
do year = death_year+2 to hbound(services);
    num_use_post_death + services{year};
    end;
drop year;
run;

(untested)

 

PG
s_lassen
Meteorite | Level 14

Something like this?

data want;
  set have;
  array services(2010:2018) service2010-service2018;
  num_use_post_death=0;
  if death_year then do _N_=max(death_year+2,2010) to hbound(services);
    num_use_post_death+services(_N_);
    end;
run;

I put in the MAX function in case you have some that died before 2008.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1288 views
  • 0 likes
  • 5 in conversation