HI,
I have a variable name which contains
DR JAMES KINDY
MISS JUME ALFINE
MA JOSEPH ABRAM LINKCON
HAROID KINDERSON GEORGE
From the abvoe line i want to remove only DR,MISS , MA and create a new Variable with Full name except the designations.
like below:
JAMES KINDY
JUME ALFINE
JOSEPH ABRAM LINKCON
HAROID KINDERSON GEORGE
If I apply tranwrd fuction it will remove only last value called "MA" not other two values, also in the same value where ever MA is it is removing from String value.
any best solution
hi kanivan,
great to see the solution , this code is working.
only thing is if two times repeats the same string DR in the begging and middile DR , need to remove the DR ony in the begging .
any idea. thank you very much ..
Please try perl regular expression
data have;
infile cards missover;
input Name &$100.;
newname=strip(prxchange('s/\bDR\b|\bMISS\b|MA\b//',-1,name));
cards;
DR JAMES KINDY
MISS JUME ALFINE
MA JOSEPH ABRAM LINKCON
HAROID KINDERSON GEORGE
;
hi Jag,
this is excellent ..brillient..great its works.
I have one small concern on the same, the data also contains middle name with DR. dont want to remove this. only in the begging of the string only need to remove any clue.
Please try the below code
newname=strip(prxchange('s/\bDR\s\b|\bMISS\s\b|MA\s\b//',-1,name));
Also, please mark the answer which was helpful to you. I see you have marked your response as answer.
hi jag,
this is scripit is not working , as it was removing everying ..
I tested this script and its working fine. Please find the output I got.
data have;
infile cards missover;
input Name &$100.;
newname=strip(prxchange('s/\bDR\s\b|\bMISS\s\b|MA\s\b//',-1,name));
cards;
DR JAMES DR. KINDY
MISS JUME ALFINE
MA JOSEPH ABRAM LINKCON
HAROID KINDERSON GEORGE
;
OUTPUT:
hi jag,
the only problem on the below code is it will not supress the DR. in the middile of the name,
where as the first record we have two DR , the begging DR removed but middile DR also should be removed.
as per the code we are searchign in the starting of the string any of the special characters(dr,mr,miss) and removing and some times they also apper in the middile of the name.
I hope it will help you
DATA HAVE;
INPUT NAME $20.;
DATALINES;
DR JOHN DAS
MISS ANNA RAFT
MA MIC JAG
JAGA TOOMBA YUOMBA
;
RUN;
DATA WANT;
SET HAVE;
DO;
NV=TRANWRD(NAME,'DR ','');
NV=TRANWRD(NV,'MISS ','');
NV=TRANWRD(NV,'MA ','');
IF FIND(NV,'')=1 THEN NV=SUBSTR(NV,2,LENGTH(NV));
OUTPUT;
END;
RUN;
hi kanivan,
great to see the solution , this code is working.
only thing is if two times repeats the same string DR in the begging and middile DR , need to remove the DR ony in the begging .
any idea. thank you very much ..
Hi, vallsas!
DATA HAVE;
INPUT NAME $20.;
DATALINES;
DR JOHN DAS
DR JOHNDR DAS
DR JOHN DRDAS
DR JOHN DR DRDAS
MISS ANNAMISS RAFT
MISS ANNA MISSRAFT
MISS ANNA MISS RAFT
MA MIC JAG
MA MICMA JAG
MA MIC MAJAG
MA MIC MA JAG
JAGA TOOMBA YUOMBA
;
RUN;
DATA WANT;
SET HAVE;
DO;
NV=TRANWRD(NAME,'DR ','');
NV=TRANWRD(NV,'MISS ','');
NV=TRANWRD(NV,'MA ','');
IF FIND(NV,'')=1 THEN NV=SUBSTR(NV,2,LENGTH(NV));
IF SUBSTR(NAME,1,3)='DR ' THEN NV_SUBSTR=SUBSTR(NAME,4,LENGTH(NAME));
ELSE IF SUBSTR(NAME,1,5)='MISS ' THEN NV_SUBSTR=SUBSTR(NAME,6,LENGTH(NAME));
ELSE IF SUBSTR(NAME,1,3)='MA ' THEN NV_SUBSTR=SUBSTR(NAME,4,LENGTH(NAME));
ELSE NV_SUBSTR=NAME;
OUTPUT;
END;
RUN;
hi thanks for the detailed code...
by using this techiique not gettign the right soultion stil..
some how the previous solution better ..
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.