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.

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 851 views
  • 0 likes
  • 5 in conversation