BookmarkSubscribeRSS Feed
teja5959
Fluorite | Level 6

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

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

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;
Kalind_Patel
Lapis Lazuli | Level 10

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 376 views
  • 0 likes
  • 4 in conversation