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.