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

Hello Experts,

 

I have the data like this : LM7613369000000091800505984.

I would like to have the 11 last caracters.

My code is 

NO1=substr(Num,11,-1)

But it doesn't work.

Could you help me please ?

Thank you !

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do this

 

data _null_;
   str = "LM7613369000000091800505984";
   last11 = substr(str, length(str)-10);
   put last11 =;
run;

 

Result:

 

last11=91800505984

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Do this

 

data _null_;
   str = "LM7613369000000091800505984";
   last11 = substr(str, length(str)-10);
   put last11 =;
run;

 

Result:

 

last11=91800505984

 

ballardw
Super User

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

 

Consider this example:

data example;
   x='LM7613369000000091800505984';
   y=substr(x,length(x)-10);
run;

And think about why -10 yields 11 characters.

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
  • 2 replies
  • 1093 views
  • 2 likes
  • 3 in conversation