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;
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!
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.