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
Hi,
data want;
set have;
name_of_hospital=substr(hospital_name,index(hospital_name,"-")+1);
run;
data want;
set have;
Hopspital_Name=scan(Hopspital_Name,2,'-');
run;
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.
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.
you can use compress function to remove '-'.
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;
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
;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.