data have ;
a b
001 NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS)
001 NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS)
001 NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS)
001 NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS)
002 NEW OTC OR RX DRUG ADDED, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
002 NEW OTC OR RX DRUG ADDED, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
002 NEW OTC OR RX DRUG ADDED, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
002 NEW OTC OR RX DRUG ADDED, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
002 NEW OTC OR RX DRUG ADDED, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
003 STUDY TREATMENT DISCONTINUED PERMANENTLY, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
003 STUDY TREATMENT DISCONTINUED PERMANENTLY, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
003 STUDY TREATMENT DISCONTINUED PERMANENTLY, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
003 STUDY TREATMENT DISCONTINUED PERMANENTLY, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
i want
001 NEW OTC OR RX DRUG ADDED
001 NEW OTC OR RX DRUG ADDED
001 NEW OTC OR RX DRUG ADDED
002 NEW OTC OR RX DRUG ADDED
002 NEW OTC OR RX DRUG ADDED
002 NEW OTC OR RX DRUG ADDED
002 NEW OTC OR RX DRUG ADDED
002 NEW OTC OR RX DRUG ADDED
003 STUDY TREATMENT DISCONTINUED PERMANENTLY
003 STUDY TREATMENT DISCONTINUED PERMANENTLY
003 STUDY TREATMENT DISCONTINUED PERMANENTLY
003 STUDY TREATMENT DISCONTINUED PERMANENTLY
Hi @teja5959
You can use the scan function:
data want;
set have;
b2 = scan(b,1,",");
drop b;
rename b2 = b;
run;
or the prxchange function:
data want;
set have;
b2 = prxchange('s/,.+//',1,b);
drop b;
rename b2 = b;
run;
Try this SAS Code:
data have;
input number texts $80.;
datalines;
001 NEW OTC OR RX DRUG ADDED, HOSPITALIZATION (INCLUDES ER VISITS)
002 NEW OTC OR RX DRUG ADDED, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
003 STUDY TREATMENT DISCONTINUED PERMANENTLY, Non-drug therapy, HOSPITALIZATION (INCLUDES ER VISITS)
;;;;
run;
data want;
set have;
texts=scan(texts,1,',');
run;
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!
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.