DATA Step, Macro, Functions and more

How to extract first 3 letters and last letter by using proc sql

Accepted Solution Solved
Reply
Highlighted
Regular Contributor
Posts: 214
Accepted Solution

How to extract first 3 letters and last letter by using proc sql

I have a variable which has values like "magnum 1", "magnum 2" "magnum 3". I need to extract first3 and last number like "MAG1"

"MAG2". How can i do this in proc sql?

 

Any help


Accepted Solutions
Solution
‎03-08-2018 05:44 AM
Super Contributor
Posts: 340

Re: How to extract first 3 letters and last letter by using proc sql

Hello,

 

proc sql;
SELECT upcase(cats(substr(x,1,3),substr(x,length(x)-1)))
FROM have;
quit;

View solution in original post


All Replies
Solution
‎03-08-2018 05:44 AM
Super Contributor
Posts: 340

Re: How to extract first 3 letters and last letter by using proc sql

Hello,

 

proc sql;
SELECT upcase(cats(substr(x,1,3),substr(x,length(x)-1)))
FROM have;
quit;
Super User
Posts: 13,583

Re: How to extract first 3 letters and last letter by using proc sql


vraj1 wrote:

I have a variable which has values like "magnum 1", "magnum 2" "magnum 3". I need to extract first3 and last number like "MAG1"

"MAG2". How can i do this in proc sql?

 

Any help


Do you have any values with fewer than 4 characters?

If you have "mag" as a value your rule would create "magg".

 

Regular Contributor
Posts: 214

Re: How to extract first 3 letters and last letter by using proc sql

Its only 3 letters:-)

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 141 views
  • 0 likes
  • 3 in conversation