BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ANLYNG
Pyrite | Level 9

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------->

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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).

View solution in original post

5 REPLIES 5
Reeza
Super User

Is that your sample data? Please show what you want as output and make sure your sample data is reflective of your actual data. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ANLYNG
Pyrite | Level 9

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

Astounding
PROC Star

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).

ANLYNG
Pyrite | Level 9

great simple solutionwhich works as wanted - thanks

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1088 views
  • 1 like
  • 4 in conversation