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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.