BookmarkSubscribeRSS Feed
KannanBaskar
Calcite | Level 5

Hi All,

Hope everyone doing good.

I would like to have some idea on the below situtaion which i have come accross recently. I have dataset called Hospitals which contain the hospital_name variable and it is having the data as mentioned below. I need to remove the country name in the every records. Please find the example below.

Obs   Hopspital_Name

1       INDIA - ABC HEALTHCARE

2       CHINA - EFF HEALTHCARE

3       USA  - GHI HEALTHCARE

4       UK - KLK HEALTHCARE

5       -


6       -


.

.

.

.

.

210  SPAIN-XYZ Healthcare.

Can you please help me how to trim the country name for 210 countries

Thanks,

Kannan

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

data want;

     set have;

     name_of_hospital=substr(hospital_name,index(hospital_name,"-")+1);

run;

stat_sas
Ammonite | Level 13

data want;

     set have;

     Hopspital_Name=scan(Hopspital_Name,2,'-');

run;

GeorgeT
Calcite | Level 5

Despite there already being two perfectly good answers, here is a third, possibly slighlty more cryptic and possibly slightly more flexible.

data want

  set have;

  Hospital_Name=prxchange('s/^.+-\s//'1,Hospital_Name);

run;

I think prxchange was introduced in SAS9.

KannanBaskar
Calcite | Level 5

Thanks George for your answers,

I have another query on the same issues. I just need to remove '-' if hospital name contain any country name. Please see the dataset below.

Obs   Hopspital_Name

1       INDIA - ABC HEALTHCARE

2       CHINA - EFF HEALTHCARE

3       USA  - GHI HEALTHCARE

4       UK - KLK HEALTHCARE

5       HAPPY - HEALTHCARE

6       WELL - HEALTHCARE

7       WEALTH - HEALTHCARE

8       FREE - HEALTHCARE

.         .

1800  AUS - HEALTHCARE

i look forwared hear from you.

Thanks in Advance,

Kannan B.

RamKumar
Fluorite | Level 6

you can use compress function to remove '-'.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

To clarify, what do you want the output to be as whilst you can use the compress function as RamKumar has mentioned you also need to know if a country is in the first part.  Do you have some kind of list in place to identify all different spellings of country?  If so then:

proc sql;

     create table WANT as

     select     OBS,

                    case     when scan(HOSPITAL_NAME,2,'-') in (select distinct COUNTRY from WORK.LIST_OF_COUNTRIES) then

                                      compress(HOSPITAL_NAME,"-")

                                  else HOSPITAL_NAME end as HOSPITAL_NAME

     from       HAVE;

quit;

art297
Opal | Level 21

Are you just trying to do something like?:

data have;

  format Hospital_Name $80.;

  input Hospital_Name 1-80;

  if countw(scan(Hospital_Name,2,'-')) eq 1 then

   Hospital_Name=compress(Hospital_Name,'-');

  else Hospital_Name=scan(Hospital_Name,2,'-');

  cards;

INDIA - ABC HEALTHCARE

CHINA - EFF HEALTHCARE

USA  - GHI HEALTHCARE

UK - KLK HEALTHCARE

HAPPY - HEALTHCARE

WELL - HEALTHCARE

WEALTH - HEALTHCARE

FREE - HEALTHCARE

AUS - HEALTHCARE

;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2222 views
  • 0 likes
  • 6 in conversation