BookmarkSubscribeRSS Feed
meetagupta
Fluorite | Level 6

Hello, below is the dataset and I want to display only those obs. where last 3 digits in the amount  ends with 999.

thanks.

 

id   amount

1    678

2    73999

3     6574

4    7699

5    672908

6    69999

 

7 REPLIES 7
Reeza
Super User
Try the SUBSTRN() function - note the N.
hashman
Ammonite | Level 13

@meetagupta:

The MOD function is your friend:

data have ;                      
  input id amount ;              
  cards ;                        
1     678                        
2   73999                        
3    6574                        
4    7699                        
5  672908                        
6   69999                        
;                                
run ;                            
                                 
data want ;                      
  set have ;                     
  last_digit = mod (amount, 10) ;
run ;                            

Kind regards

Paul D. 

Tom
Super User Tom
Super User

Is account a number (and if so why?) or a character string?  The subject line says number and the example data appears left justified like a character string.  Depending on which you have use one of these methods.

where mod(account,1000) = 999 ;
where substrn(account,length(account)-2)='999';

 

hashman
Ammonite | Level 13

@Tom:

It seems it says "amount" rather than "account". And it's my understanding that by "last digit", the OP means the least significant, i.e. rightmost digit.

 

If the variable in question a digit string, methinks the simplest is:

  last_digit = char (amountC, length (amountC)) ;

Plus, it's convenient that CHAR returns $1 suitable for a single digit character.

 

Kind regards

Paul D. 

Tom
Super User Tom
Super User

Not sure how the last digit can ever equal 999.

hashman
Ammonite | Level 13

@Tom: Me neither. A case where the title mismatches the content. 

ballardw
Super User

Not the first subject content disagreement, even today:

 

I would go with the

Hello, below is the dataset and I want to display only those obs. where last 3 digits in the amount  ends with 999.

thanks.

 

But would also be concerned about potential decimal portion of the value.

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 9165 views
  • 3 likes
  • 5 in conversation