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

Could somebody help me to deal with this problem, thanks so much.

 

Basicly, I had thousands of PIN, dates, and mark (which I pasted below). I need to subtract dates between first "new start <400" till last "keep start <400". For example, for PIN=100, I subtract last "keep start <400" 1/7/2010 - first "new start <400" 2/25/2009.

Then, I will need another subtraction for the same pin between "keep start <400" 11/24/2015-  "new start <400" 3/2/2011.

 

PINDATE_COLLECTEDmark
1002/25/2009new START <400
1006/8/2009keep START  <400
1001/7/2010keep START  <400
1003/2/2011new START  <400
1004/26/2011keep START  <400
1006/29/2011keep START  <400
10012/14/2011keep START  <400
1006/6/2012keep START  <400
10012/12/2012keep START  <400
1006/12/2013keep START  <400
10012/11/2013keep START  <400
1004/18/2014keep START  <400
10010/7/2014keep START  <400
10012/16/2014keep START  <400
1003/13/2015keep START  <400
10011/24/2015keep START  <400

 

Any suggestion would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Try:

 

data want;

set have;

by PIN mark notsorted;

if first.PIN then baseline = . ;

retain baseline;

if mark = "new start <400" then baseline = date;

if last.mark and mark = "keep START  <400" then difference = date - baseline;

drop baseline;

run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Try:

 

data want;

set have;

by PIN mark notsorted;

if first.PIN then baseline = . ;

retain baseline;

if mark = "new start <400" then baseline = date;

if last.mark and mark = "keep START  <400" then difference = date - baseline;

drop baseline;

run;

linda0910
Obsidian | Level 7

Thanks so much. That's exactly what I want. 

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
  • 2 replies
  • 1570 views
  • 0 likes
  • 2 in conversation