DATA Step, Macro, Functions and more

Need help

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Need help

Hi ,

I have a date set with variables ID, lead id , ctime , utime, name.

 

Here i want to extract the person name utime start date and end date.

 

1) ID is same but leads will change, according to that i need to extract the name (i want to know the person name who worked for which period )

 

Data set :

 

ID

lead id

ctime

utime

Name

2254

35217

6/06/2009

6/06/2009

Jack

2254

35217

6/06/2009

29/06/2009

Jack

2254

35217

6/06/2009

30/08/2010

Jack

2254

35217

6/06/2009

3/09/2010

Jack

2254

35217

6/06/2009

6/09/2010

Jack

2254

35217

6/06/2009

26/11/2010

Jack

2254

35217

6/06/2009

29/11/2010

Jack

2254

35267

6/06/2009

1/12/2010

Prem

2254

35267

6/06/2009

29/12/2010

Prem

2254

35267

6/06/2009

8/02/2011

Prem

2254

35267

6/06/2009

14/03/2011

Prem

2254

35217

6/06/2009

16/03/2011

Jack

2254

35217

6/06/2009

20/04/2011

Jack

2254

35217

6/06/2009

10/06/2011

Jack

2254

35217

6/06/2009

30/06/2011

Jack

2254

35217

6/06/2009

6/07/2011

Jack

2254

35217

6/06/2009

14/07/2011

Jack

 

In the above data set . Jack worked from 6/06/2009 to 29/11/2010 under ID 2254 and  under lead id 35217.

after that Prem worked from 1/12/2010 to 14/03/2011 under ID 2254 and  under lead id 35267.

 

here again Jack worked from 16/03/2011 to 16/03/2011 under ID 2254 and  under lead id 35217.

 

output should be :

ID

lead id

ctime

utime

Name

2254

35217

6/06/2009

6/06/2009

Jack

 
 

2254

35217

6/06/2009

29/11/2010

Jack

2254

35267

6/06/2009

1/12/2010

Prem

  
  

2254

35267

6/06/2009

14/03/2011

Prem

2254

35217

6/06/2009

16/03/2011

Jack

 
 

2254

35217

6/06/2009

14/07/2011

Jack

 

 


Accepted Solutions
Solution
2 weeks ago
PROC Star
Posts: 1,218

Re: Need help

Something like this?

 

data have;
input ID $ lead_id $ (ctime utime)(:ddmmyy10.) Name $;
format ctime utime ddmmyy10.;
datalines;
2254 35217 6/06/2009 6/06/2009 Jack
2254 35217 6/06/2009 29/06/2009 Jack
2254 35217 6/06/2009 30/08/2010 Jack 
2254 35217 6/06/2009 3/09/2010 Jack
2254 35217 6/06/2009 6/09/2010 Jack
2254 35217 6/06/2009 26/11/2010 Jack
2254 35217 6/06/2009 29/11/2010 Jack
2254 35267 6/06/2009 1/12/2010 Prem
2254 35267 6/06/2009 29/12/2010 Prem
2254 35267 6/06/2009 8/02/2011 Prem
2254 35267 6/06/2009 14/03/2011 Prem
2254 35217 6/06/2009 16/03/2011 Jack
2254 35217 6/06/2009 20/04/2011 Jack
2254 35217 6/06/2009 10/06/2011 Jack
2254 35217 6/06/2009 30/06/2011 Jack
2254 35217 6/06/2009 6/07/2011 Jack
2254 35217 6/06/2009 14/07/2011 Jack
;

data want;
   set have;
   by lead_id notsorted;
   if first.lead_id or last.lead_id;
run;

View solution in original post


All Replies
Solution
2 weeks ago
PROC Star
Posts: 1,218

Re: Need help

Something like this?

 

data have;
input ID $ lead_id $ (ctime utime)(:ddmmyy10.) Name $;
format ctime utime ddmmyy10.;
datalines;
2254 35217 6/06/2009 6/06/2009 Jack
2254 35217 6/06/2009 29/06/2009 Jack
2254 35217 6/06/2009 30/08/2010 Jack 
2254 35217 6/06/2009 3/09/2010 Jack
2254 35217 6/06/2009 6/09/2010 Jack
2254 35217 6/06/2009 26/11/2010 Jack
2254 35217 6/06/2009 29/11/2010 Jack
2254 35267 6/06/2009 1/12/2010 Prem
2254 35267 6/06/2009 29/12/2010 Prem
2254 35267 6/06/2009 8/02/2011 Prem
2254 35267 6/06/2009 14/03/2011 Prem
2254 35217 6/06/2009 16/03/2011 Jack
2254 35217 6/06/2009 20/04/2011 Jack
2254 35217 6/06/2009 10/06/2011 Jack
2254 35217 6/06/2009 30/06/2011 Jack
2254 35217 6/06/2009 6/07/2011 Jack
2254 35217 6/06/2009 14/07/2011 Jack
;

data want;
   set have;
   by lead_id notsorted;
   if first.lead_id or last.lead_id;
run;
Occasional Contributor
Posts: 8

Re: Need help

Thanks for the quick reply....

 

In this case Jack worked two different periods.

 

 

Occasional Contributor
Posts: 8

Re: Need help

Thank you very much....yes, this code suites my requirement. i will test my data and if i have any problem will come back.

 

Thanks again.

PROC Star
Posts: 1,218

Re: Need help

Anytime. Feel free to reach out if you encounter problems. 

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 90 views
  • 1 like
  • 2 in conversation