Search code examples
sas

how to separate names into 2 parts?


I have a name list:

data nurse_0;
input nms $28. ;
 cards;
Abcd Efgxxeg, BSN, RN
Dudng Nioll, RN, CCM
Doujh Keeloou, RN
Hardlop Aceed RN BSN
Jnmjkl Tuutt, BSN  RN, CCM
Kommmbbey Maxxt, RN, CM
;
run;

and I want split the first name and rest of the names w/o any change into 2 colums, first_nm and last_nm:

 first_nm  last_nm
 Abcd      Efgxxeg, BSN, RN
 Dudng     Nioll, RN, CCM
 Doujh     Keeloou, RN
 Hardlop   Aceed RN BSN
 Jnmjkl    Tuutt, BSN  RN, CCM
 Kommmbbey Maxxt, RN, CM

Solution

  • data want;
       set nurse_0;
       first_nm = scan(nms, 1);
       last_nm = substr(nms, find(nms, ' ') + 1);
       drop nms;
    run;
    

    Result:

    first_nm   last_nm
    Abcd       Efgxxeg, BSN, RN
    Dudng      Nioll, RN, CCM
    Doujh      Keeloou, RN
    Hardlop    Aceed RN BSN
    Jnmjkl     Tuutt, BSN  RN, CCM
    Kommmbbey  Maxxt, RN, CM