Hi,
I tried to find text from the right before a underscore, but the code didn't work. Any help is much appreciated. Thanks.
data one;
input name $1-18;
cards;
abc_cost_mean
abc_visit_meanu
Claim_Visits_Sum
Claim_Cost_all_Sum
;
data two;
set one;
name=compress(name);
length name2 $10;
CALL SCAN( name, -1, last_pos, last_length);
name2 = substrn( name, last_pos , last_length);
run;
proc print; run;
Edited. Desired results as below, for name (original) and name2 (derived):
abc_cost_mean mean
abc_visit_meanu meanu
Claim_Visits_Sum Sum
Claim_Cost_all_Sum Sum
What is your desired result here?
Thanks for the reminder. Now added in the original post.
Do like this
data one;
input name $1-30;
cards;
abc_cost_meanabc_visit_meanu
Claim_Visits_Sum
Claim_Cost_all_Sum
;
data two;
set one;
name2=substr(name, findc(name,'_','b')+1);
run;
I thought I tried scan(var, -1,"_") and it didn't work. But apparently I used it wrong. Your code works. Thanks a lot. And thanks all for the help.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.