BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hello_there
Lapis Lazuli | Level 10
data have;
infill datalines dsd dlm=",':
input name $ @@;
red, orange, yellow, blue, green, indigo, violet, purple, turquoise, pink
;
run;

data want;
set have;
if name="p " /* what is a function that deals with partial character strings*/
;
run;


Hi, I'm trying to find a function where I can condition a data step to return back only values that match the partial character string?

 

could I receive some assistance? thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Like this?

data sample;
  infile datalines dsd dlm=",";
  input name $ @@;
  if upcase(substr(name,1,1))='P';
  datalines;
red, orange, yellow, blue, green, indigo, violet, purple, turquoise, pink
;
run;

 ...or this:


data sample;
  infile datalines dsd dlm=",";
  input name $ @@;
  if upcase(name)=:'P';
  datalines;
red, orange, yellow, blue, green, indigo, violet, purple, turquoise, pink
;
run;

View solution in original post

6 REPLIES 6
HB
Barite | Level 11 HB
Barite | Level 11

There are a lot of ways to do thins i would guess.

I would try

data want;
set have;
match_name = find (name, 'p','i');
if match_name > 0;
drop match_name;
run;

 Returns purple and pink. 

Reeza
Super User

FIND() 

INDEX()

Colon (=:), if looking for matches at the start of strings.

 


@Hello_there wrote:
data have;
infill datalines dsd dlm=",':
input name $ @@;
red, orange, yellow, blue, green, indigo, violet, purple, turquoise, pink
;
run;

data want;
set have;
if name="p " /* what is a function that deals with partial character strings*/
;
run;


Hi, I'm trying to find a function where I can condition a data step to return back only values that match the partial character string?

 

could I receive some assistance? thanks


 

ballardw
Super User

What exactly do you mean by ="p "? That it contains a p anywhere in the string? That the exact string p followed by a space is in the string (which means no matches in your example)? Starts with a p?

 

You really need to show exactly what you expect for the output as there may be several ways and may not match your need.

 

 

Hello_there
Lapis Lazuli | Level 10
Hi, sorry for the confusion.

I'm looking for a function that select the colors that start with "p"
Patrick
Opal | Level 21

Like this?

data sample;
  infile datalines dsd dlm=",";
  input name $ @@;
  if upcase(substr(name,1,1))='P';
  datalines;
red, orange, yellow, blue, green, indigo, violet, purple, turquoise, pink
;
run;

 ...or this:


data sample;
  infile datalines dsd dlm=",";
  input name $ @@;
  if upcase(name)=:'P';
  datalines;
red, orange, yellow, blue, green, indigo, violet, purple, turquoise, pink
;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 589 views
  • 6 likes
  • 6 in conversation