- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-22-2009 11:11 AM
(1474 views)
I'm not that good at reg exp. I tried my luck ..was not sucessful. Need your help on this.
I have a filed called "Drug_name". It will have the list of drugs. example: Paracetmol 4.8MG VIAL
The task is to extract the digits from it. in this case its 4.8.
Possible scenarios:
the number of digits vary between 1 and 4
so we need to have an or condition for number of digits d d\d d\d\d d\d\d\d
and we should consider decimal also between two digits as in the example.
the values should go to the filed called strength,.
in this case strength is 4.8
Thanks,
SASphile
I have a filed called "Drug_name". It will have the list of drugs. example: Paracetmol 4.8MG VIAL
The task is to extract the digits from it. in this case its 4.8.
Possible scenarios:
the number of digits vary between 1 and 4
so we need to have an or condition for number of digits d d\d d\d\d d\d\d\d
and we should consider decimal also between two digits as in the example.
the values should go to the filed called strength,.
in this case strength is 4.8
Thanks,
SASphile
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use ANYALPHA to test if non-numeric present, then use COMPRESS function to remove chars A-Z after UPCASE, in a DATA step to assign a SAS variable, then use INPUT (convert to SAS NUMERIC) and PUT function (to convert back to a "formatted" CHARACTER type variable, displayed as a number).
Scott Barry
SBBWorks, Inc.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello SASPhile,
Here is how your program could look like:
data T01_input;
length drug $50;
infile cards delimiter=',';
input id drug;
cards;
1,Paracetmol 4.8MG VIA
2,Paracetmol 423.23422238MG VIA
3,Paracetmol 42342.38MG VIA
4,Paracetmol x.8MG VIA
;
run;
data T02_output;
set T01_input;
length myDigits $50;
if prxmatch('/.* \d{1,4}\.\d+MG .*/',drug)
then myDigits = prxchange('s/.* (\d{1,4}\.\d+)MG .*/$1/', -1, drug);
else myDigits = "NOT FOUND";
run;
proc print data=T02_output;
run;
You would get the following output:
1 Paracetmol 4.8MG VIA 1 4.8
2 Paracetmol 423.23422238MG VIA 2 423.23422238
3 Paracetmol 42342.38MG VIA 3 NOT FOUND
4 Paracetmol x.8MG VIA 4 NOT FOUND
If you need to convert the myDigit string to number ... use the input function.
Does it help?
Yoba
Here is how your program could look like:
data T01_input;
length drug $50;
infile cards delimiter=',';
input id drug;
cards;
1,Paracetmol 4.8MG VIA
2,Paracetmol 423.23422238MG VIA
3,Paracetmol 42342.38MG VIA
4,Paracetmol x.8MG VIA
;
run;
data T02_output;
set T01_input;
length myDigits $50;
if prxmatch('/.* \d{1,4}\.\d+MG .*/',drug)
then myDigits = prxchange('s/.* (\d{1,4}\.\d+)MG .*/$1/', -1, drug);
else myDigits = "NOT FOUND";
run;
proc print data=T02_output;
run;
You would get the following output:
1 Paracetmol 4.8MG VIA 1 4.8
2 Paracetmol 423.23422238MG VIA 2 423.23422238
3 Paracetmol 42342.38MG VIA 3 NOT FOUND
4 Paracetmol x.8MG VIA 4 NOT FOUND
If you need to convert the myDigit string to number ... use the input function.
Does it help?
Yoba
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thnaks yoba!