Hi,
I got a large numbers of events which is a sort of interval where I want to count days from a start event point (date) to an end point(another date). I need the first start1 og end1/end2 in every interval. Do you have any smart suggestion to do that? after the specific observation has been output i will count the days by retain. Thanks in advance.
idx start1 ----->
idx start1
idx start1
idx end1------->
idx start1 ----->
idx start1
idx start1
idx end1------->
idy start1 ----->
idy start1
idy start1
idy end2------->
You'll probably see a few somewhat similar solutions. Here's the variation I would use:
data want;
set have;
by caseid type notsorted;
if (first.type and type='typex') or (last.type and type='typey');
run;
You have to match whatever is in your data (is it "typey" or "type y" for example).
Is that your sample data? Please show what you want as output and make sure your sample data is reflective of your actual data.
Show test data in the form of a datastep and what what you want the output to look like. We can't tell anything from what you have posted.
The data is case date events and I want the first typex as startpoint date and always typey as end date. I think I need a counter which os reset by the endtype??? any suggestions are welcome.
my data looks like this
caseid, date, type
122220 12/7/2016 typex ----->want this one in output, first typex.sorted by date and caseid
122220 7/8/2016 typex
122220 7/9/2016 type x
122220 10/10/2016 typey------->want this one in output, type y
122220 17/10/2016 typex ----->want this one in output, first typex, sorted by date and caseid
122220 24/10/2016 typex
122220 7/9/2016 typex
122220 10/10/2016 typey------->want this one in output, type y
122300 3/3/2016 typex ----->want this one in output, first typex sorted by date and caseid
122300 10/3/2016 typex
122300 7/9/2016 typex
122300 10/10/2016 type y------->want this one in output, type y
122300 17/10/2016 typex ----->want this one in output, first typex, sorted by date and caseid
122300 24/10/2016 typex
122300 26/10/2016 type x
122300 26/11/2016 type y------->want this one in output, type y
You'll probably see a few somewhat similar solutions. Here's the variation I would use:
data want;
set have;
by caseid type notsorted;
if (first.type and type='typex') or (last.type and type='typey');
run;
You have to match whatever is in your data (is it "typey" or "type y" for example).
great simple solutionwhich works as wanted - thanks
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.