Help using Base SAS procedures

substr the last few letters

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

substr the last few letters

I would like to know how to get the final few letters of a string?


Accepted Solutions
Solution
‎11-16-2011 11:26 AM
PROC Star
Posts: 7,363

substr the last few letters

You could always use substr using the length function to get the variable's starting point. e.g.:

data want;

  set sashelp.class;

  last3chars=substr(name,length(name)-2);

run;

View solution in original post


All Replies
Solution
‎11-16-2011 11:26 AM
PROC Star
Posts: 7,363

substr the last few letters

You could always use substr using the length function to get the variable's starting point. e.g.:

data want;

  set sashelp.class;

  last3chars=substr(name,length(name)-2);

run;

Super Contributor
Posts: 1,636

substr the last few letters

If you want last n letters then you should start from length(of your variable)-n+1.

data want_last_2;

  input AA $;

  newaa=substr(aa,length(aa)-1);

cards;

sdfgh

nhdsadfg

cedsas

oiugdbah

;

proc print;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 169 views
  • 0 likes
  • 3 in conversation