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.
Please post example data (in a data step with datalines), and what you expect out of it.
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;
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)
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.
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!
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.