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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1388 views
  • 0 likes
  • 2 in conversation