DATA Step, Macro, Functions and more

How to retrieve a second transaction from a customer acc_no=100 ?

Reply
New Contributor
Posts: 2

How to retrieve a second transaction from a customer acc_no=100 ?

Acc_NoTransaction_DateTransaction_Amount
1001-Jul-151000
1002-Jul-152000
1003-Jul-153000
1004-Jul-154000
1005-Jul-155000
1016-Jul-156000
1017-Jul-157000
1018-Jul-152500
1019-Jul-15500
Contributor
Posts: 44

Re: How to retrieve a second transaction from a customer acc_no=100 ?

proc sort data=have;

  by Acc_No Transaction_Date;

run;

data have;

  set have ;

  by Acc_No Transaction_Date;

retain order 0;

if first.Acc_no then order = 0;

order+1;

run;

data want;

  set have;

  if order = 2;

run;

Super Contributor
Posts: 305

Re: How to retrieve a second transaction from a customer acc_no=100 ?

Hello,

data have;
input Acc_No Transaction_Date date8. Transaction_Amount ;
format Transaction_Date date9.;
datalines;
100 1-Jul-15 1000
100 2-Jul-15 2000
100 3-Jul-15 3000
100 4-Jul-15 4000
100 5-Jul-15 5000
101 6-Jul-15 6000
101 7-Jul-15 7000
101 8-Jul-15 2500
101 9-Jul-15 500
;

data want;
set have (keep=Acc_No) ;
by Acc_No;
set have(firstobs=2 drop=Acc_No);

if first.Acc_No;
run;

Occasional Contributor
Posts: 17

Re: How to retrieve a second transaction from a customer acc_no=100 ?

Data a;

  INFILE CARDS;

  INPUT Acc_no @;

  IF Acc_no = 100;

  INPUT Transaction_dateSmiley Very HappyATE9. Trans_Amt;

DATALINES;

100 1-Jul-15 1000

100 2-Jul-15 2000

100 3-Jul-15 3000

100 4-Jul-15 4000

100 5-Jul-15 5000

101 6-Jul-15 6000

101 7-Jul-15 7000

101 8-Jul-15 2500

101 9-Jul-15 500

;

PROC PRINT DATA = a (FIRSTOBS =2 OBS=2);

  FORMAT Transaction_date DATE9.;

RUN;

PROC Star
Posts: 1,561

Re: How to retrieve a second transaction from a customer acc_no=100 ?

data have;

input Acc_No Transaction_Date date8. Transaction_Amount ;

format Transaction_Date date9.;

datalines;

100 1-Jul-15 1000

100 2-Jul-15 2000

100 3-Jul-15 3000

100 4-Jul-15 4000

100 5-Jul-15 5000

101 6-Jul-15 6000

101 7-Jul-15 7000

101 8-Jul-15 2500

101 9-Jul-15 500

;

data want;

  set have;

  by Acc_No;

  if lag(first.Acc_No);

  putlog Transaction_Date;

run;

02JUL2015

07JUL2015


Add a where clause if you need one customer only.

Ask a Question
Discussion stats
  • 4 replies
  • 262 views
  • 0 likes
  • 5 in conversation