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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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