hai all i have a doubt in string extraction.I can use several methods like substr(),index() to extarct 245 from whole string.But i couldn't get any result.Please help me
site
245-abcdefhg
Thanks
krishna
Then you haven't provided enough information, works for me just fine, I've added the input to convert to numeric.
This also shows the compress method:
data have;
informat string $25.;
input string;
cards;
245-abcdefhg
;
run;
data want;
set have;
want=input(scan(string, 1, "-"), 8. );
want2=input(compress(string,, 'kd'), 8.);
type=vtype(want);
type2=vtype(want2);
put want;
put want2;
put type;
put type2;
run;
LOG:
1417 data want;
1418 set have;
1419 want=input(scan(string, 1, "-"), 8. );
1420 want2=input(compress(string,, 'kd'), 8.);
1421 type=vtype(want);
1422 type2=vtype(want2);
1423 put want;
1424 put want2;
1425 put type;
1426 put type2;
1427 run;
245
245
N
N
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds
Are all strings in that format? Do you need it as numeric or character?
Try scan
string245=scan(string, 1, "-");
need to get it as numeric
Hai Reeza No result found :smileyplain:
Then you haven't provided enough information, works for me just fine, I've added the input to convert to numeric.
This also shows the compress method:
data have;
informat string $25.;
input string;
cards;
245-abcdefhg
;
run;
data want;
set have;
want=input(scan(string, 1, "-"), 8. );
want2=input(compress(string,, 'kd'), 8.);
type=vtype(want);
type2=vtype(want2);
put want;
put want2;
put type;
put type2;
run;
LOG:
1417 data want;
1418 set have;
1419 want=input(scan(string, 1, "-"), 8. );
1420 want2=input(compress(string,, 'kd'), 8.);
1421 type=vtype(want);
1422 type2=vtype(want2);
1423 put want;
1424 put want2;
1425 put type;
1426 put type2;
1427 run;
245
245
N
N
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.01 seconds
Thanks Reeza
data have;
input site $25.;
site_number=input(scan(site, 1, "-"),8.);
cards;
245-abcdefhg
;
thanks Arthur tabachneck
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.