BookmarkSubscribeRSS Feed
teja5959
Obsidian | Level 7

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 981 views
  • 0 likes
  • 4 in conversation