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
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;
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.
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
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.
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;
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 16. 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.