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

 


data test;
input ssn $9. ee_id$ EE_pyin $10. payamt;
cards;
093443789 322189 2018-06-01 1200
093443789 322189 2018-06-15 1200
093443789 322189 2018-06-29 1200
093443789 322189 2018-07-01 1300
094646665 112782 2018-03-09 2807
094646665 112782 2018-09-21 0054
;run;

 

in the above program there are 2 different ssn(social secuirty number), i want to count how many times he has paid.Till here it is working fine .But i dont want to include the last payment or you can say exclude the latest date for every ssn and then output all others as you can see below.

 

Pls help!!

 

proc sort data=test;by ssn;run;

 

data a c1 c2 c3;
set test;
by ssn;
if first.ssn then c=0;
c+1;
if c=1 then output c1;
if c=2 then output c2;
if c=3 then output c3;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

I don't understand what you try to do with c1, c2 and c3 in you data step? Do you want to create separate datas sets for each count or? 

 

If you simply want to exclude the latest payment, then do

 

data want;
   set test;
   by ssn; 
   if first.ssn then c=0;
   c+1;
   if not last.ssn;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

I don't understand what you try to do with c1, c2 and c3 in you data step? Do you want to create separate datas sets for each count or? 

 

If you simply want to exclude the latest payment, then do

 

data want;
   set test;
   by ssn; 
   if first.ssn then c=0;
   c+1;
   if not last.ssn;
run;
adi121
Fluorite | Level 6

Hi dray,

 

u are right , i wanted to put records with count as 1 ,2,3 in separate datasets and ignore the last one and do some calculations with it.

 

Anyway ur solution is perfect.

 

Thanks!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 533 views
  • 0 likes
  • 2 in conversation