BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cmemtsa
Quartz | Level 8
data T;
input ID $ L $;
Datalines;
1 3/42514
2 11/761
3 350
;

Hi,

I have a column L with data and I want to extract only numbers after the slash (\). If there's no slash, then the whole number i.e. the output should be

1  42514

2 761

3 350

Is it feasible?

 

Thank you in advance for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

You can use the scan-function to extract a "word" from a string. If the second argument is negative, scan starts from the right side.

data want;
   set T;
   
   newL = scan(L, -1);
run;

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

You can use the scan-function to extract a "word" from a string. If the second argument is negative, scan starts from the right side.

data want;
   set T;
   
   newL = scan(L, -1);
run;
cmemtsa
Quartz | Level 8

Yes, this works!

 

Is there a way to do it also in proc sql?

ballardw
Super User

The SCAN function works in SAS Proc SQL.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1747 views
  • 2 likes
  • 3 in conversation