DATA Step, Macro, Functions and more

Pick up the date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Pick up the date

Hi

 

I have the below data set and I would like to pick up the mth_end_dt when SOR from 1 to any number.

 

data test;

informat MTH_END_DT date9.;

input CLNT_NO MTH_END_DT SOR;

format MTH_END_DT date9.;

cards;

1 31-Mar-14 1

1 30-Apr-14 1

1 31-May-14 2

1 30-Jun-14 2

1 31-Jul-14 3

1 31-Aug-14 3

1 30-Sep-14 3

1 31-Oct-14 3

1 30-Nov-14 1

1 31-Dec-14 3

1 31-Jan-15 3

1 28-Feb-15 6

;

run;

 

Help me

 

Thanks


Accepted Solutions
Solution
‎02-17-2016 09:48 AM
Super Contributor
Posts: 490

Re: Pick up the date

maybe this what you want

 

data want ;
set test;
prev=lag(sor);
if prev=1 and sor ~=1;
drop prev;
run;

View solution in original post


All Replies
Super Contributor
Posts: 490

Re: Pick up the date

Can you explian better what you want to do? Could you give example of your desired output?

Occasional Contributor
Posts: 17

Re: Pick up the date

Like in the in the row number 3 I need the date because previous SOR is 1. In the 10th row I need date because previous SOR is 1
Solution
‎02-17-2016 09:48 AM
Super Contributor
Posts: 490

Re: Pick up the date

maybe this what you want

 

data want ;
set test;
prev=lag(sor);
if prev=1 and sor ~=1;
drop prev;
run;
Trusted Advisor
Posts: 1,115

Re: Pick up the date

Hi @umesh1,

 

If your real data contain more than one client, you may want to amend the IF condition in @mohamed_zaki's data step as shown below. Otherwise the first observation of a client might be selected because the previous client's last observation had SOR=1. 

if prev=1 and sor ~=1 and clnt_no=lag(clnt_no);

However, this modification would be redundant if the first observation of each client had SOR=1.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 243 views
  • 1 like
  • 3 in conversation