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

I have a list of records by account and looking to only capture data (earliest) when there is an interest rate change.

 

HAVE

Acct    Date     Rate

123     Jan1      2.3

123     Jan2      2.3

123     Jan3      3.4

123     Jan4      3.4

123     Jan5      3.4

123     Jan6      5

345     Jan1      1.2

345     Jan2      1.2

345     Jan3      2

345     Jan4      2.4

345     Jan5      2.4

345     Jan6      3

345     Jan7      3

and so on for many accts...

 

WANT  (only rate changes - including the first one)

Acct    Date     Rate

123     Jan1      2.3

123     Jan3      3.4

123     Jan6      5

345     Jan1      1.2

345     Jan3      2

345     Jan4      2.4

345     Jan6      3

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the below code

 

proc sort data=have;
by acct rate date;
run;

data want;
set have;
by acct rate date;
if first.rate;
run;
Thanks,
Jag

View solution in original post

6 REPLIES 6
Jagadishkatam
Amethyst | Level 16

Please try the below code

 

proc sort data=have;
by acct rate date;
run;

data want;
set have;
by acct rate date;
if first.rate;
run;
Thanks,
Jag
ballardw
Super User

Assuming the data is sorted by acct and date.

 

data want;
   set have;
   by acct  notsorted rate;
   if first.rate;
run;
Astounding
PROC Star

I believe NOTSORTED applies to the preceding variable name.  If that's right, a slight variation is called for:

 

data want;
   set have;
   by acct rate notsorted;
   if first.rate;
run;
ballardw
Super User

@Astounding wrote:

I believe NOTSORTED applies to the preceding variable name.  If that's right, a slight variation is called for:

 

data want;
   set have;
   by acct rate notsorted;
   if first.rate;
run;

Either works:

From the documentation for Notsorted on a BY  statement:

The NOTSORTED option applies to all of the variables in the BY statement. You can specify the NOTSORTED option anywhere within the BY statement.

 

hashman
Ammonite | Level 13

@podarum:

data have ;                    
  input Acct Date :$4. Rate ;  
  cards ;                      
123     Jan1      2.3          
123     Jan2      2.3          
123     Jan3      3.4          
123     Jan4      3.4          
123     Jan5      3.4          
123     Jan6      5            
345     Jan1      1.2          
345     Jan2      1.2          
345     Jan3      2            
345     Jan4      2.4          
345     Jan5      2.4          
345     Jan6      3            
345     Jan7      3            
;                              
run ;                          
                               
data want (drop = _:) ;        
  set have ;                   
  by acct ;                    
  _r = lag (rate) ;            
  if first.acct or _r ne rate ;
run ;                          

Kind regards

Paul D. 

podarum
Quartz | Level 8

Thanks everyone for the awesome responses.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1043 views
  • 1 like
  • 5 in conversation