Hello,
how can I cut off part of sting like in below example:
VAR |
USE_01 |
USE_12 |
USE_03 |
I want to keep only numbers without "0" -> so result should be 1,12,3
How can I achieve this?
data want;
set have;
part_of_string = input(scan(var,2,'_'),3.);
run;
Hello,
You could fix this with a data step and tranwrd. Below you can see an example (with example dataset) that gives the result you want in 2 steps.
data work.sastest;
input VAR1 $char6.;
format VAR1 char6.;
datalines ;
USE_01
USE_12
USE_03
;
run;
data work.sastest2;
set work.sastest;
VAR2= tranwrd(VAR1,'USE_','');
VAR3= tranwrd(VAR2,'0','');
run;
Hope this helps you!
I want to keep only numbers without "0" -> so result should be 1,12,3
It's really hard to generalize from such a small example. So let me ask a few questions
data want;
set have;
part_of_string = input(scan(var,2,'_'),3.);
run;
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.