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

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

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11

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

4 REPLIES 4
mohamed_zaki
Barite | Level 11

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

umesh1
Fluorite | Level 6
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
mohamed_zaki
Barite | Level 11

maybe this what you want

 

data want ;
set test;
prev=lag(sor);
if prev=1 and sor ~=1;
drop prev;
run;
FreelanceReinh
Jade | Level 19

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.

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