- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are all strings in that format? Do you need it as numeric or character?
Try scan
string245=scan(string, 1, "-");
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
need to get it as numeric
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hai Reeza No result found :smileyplain:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Reeza
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input site $25.;
site_number=input(scan(site, 1, "-"),8.);
cards;
245-abcdefhg
;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thanks Arthur tabachneck