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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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