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

I would lik eto know whaich sas function to use to get all orders ending with 01. Please reply

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
if substr(var,length(var)-1,2)='01'; 

View solution in original post

6 REPLIES 6
Amir
PROC Star

Please provide some context, for example:

 

  1. Is the data character or numeric?
  2. Will there ever be decimal numbers?
  3. If decimal, should the decimal be portion be ignored or used?
  4. Please provide some data in the form of a data step using datalines showing before and after the function is applied.

 

Amir.

avatar
Fluorite | Level 6

it is character data 

 

585452101
571629201
585175701
24968566
579876301
575507505
184126254
184021353
577099102

Amir
PROC Star

Thank you. You could try:

 

data have;
   input order_num $10.;
   datalines;
585452101
571629201
585175701
24968566
579876301
575507505
184126254
184021353
577099102
;

data want;
   set have;

   if left(reverse(order_num)) =: '10';
run;

 

Amir.

 

PaigeMiller
Diamond | Level 26

Let's suppose the order number is in a character variable named ORDER_NUM. Then in a SAS data step

 

if reverse(trim(order_num))=:'10';

 

--
Paige Miller
novinosrin
Tourmaline | Level 20
if substr(var,length(var)-1,2)='01'; 
novinosrin
Tourmaline | Level 20

data have;
input var $20.;
cards;
585452101
571629201
585175701
24968566
579876301
575507505
184126254
184021353
577099102
;

data want;
set have;
if substr(var,length(var)-1,2)='01';
run;

/*or indentify/flag*/

data want;
set have;
if substr(var,length(var)-1,2)='01' then flag=1;
run;


hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1305 views
  • 0 likes
  • 4 in conversation