BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
luvscandy27
Quartz | Level 8

Hello everyone, I have a variable which contains items such as:

1.  Symptoms, signs, and abnormal clinical and laboratory findings

2. Injury and poisoning

 

I only want to keep the character portion: 

Symptoms, signs, and abnormal clinical and laboratory findings

Injury and poisoning

 

Could someone please help me? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you know that every value has that numeric prefix then just remove the first "word".

want=left(substrn(string,1+length(scan(string,1,' '))));

Otherwise you will have to work harder first to figure out if the string does have the prefix.

data have ;
  input string $CHAR80. ;
cards4;
1.  Symptoms, signs, and abnormal clinical and laboratory findings
2. Injury and poisoning
;;;;

data want ;
  set have;
  new_string = prxchange('s/^ *\d+\. +(.*)$/\1/',1,string);
run;

Tom_0-1686680043413.png

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Use the COMPRESS function.

 

 

variable = compress(variable,,'d');

 

 

--
Paige Miller
luvscandy27
Quartz | Level 8

This method does not remove the . as well ?

PaigeMiller
Diamond | Level 26

@luvscandy27 wrote:

This method does not remove the . as well ?


Please give us a complete description of the problem. Show us representative examples.

--
Paige Miller
Reeza
Super User

I would find the first period and remove from there onwards using substring.

Compress may inadvertenly remove any other numeric/periods.

However, these were likely used to order the data so assuming you don't need that you'll be fine. 

 

x=findc(variable, '.');
want = substr(variable, x);
Tom
Super User Tom
Super User

If you know that every value has that numeric prefix then just remove the first "word".

want=left(substrn(string,1+length(scan(string,1,' '))));

Otherwise you will have to work harder first to figure out if the string does have the prefix.

data have ;
  input string $CHAR80. ;
cards4;
1.  Symptoms, signs, and abnormal clinical and laboratory findings
2. Injury and poisoning
;;;;

data want ;
  set have;
  new_string = prxchange('s/^ *\d+\. +(.*)$/\1/',1,string);
run;

Tom_0-1686680043413.png

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 213 views
  • 0 likes
  • 4 in conversation