BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fredbell
Fluorite | Level 6

Hello

I am attempting to query all records from a table where VQueue ends with .CT
Help please.

proc sql;
create table Queue as
select * 
  from hierarchy
   WHERE VQueue = '*.CT';
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:
SAS has a lot of string processing functions (such as FIND, FINDW, INDEX, INDEXC, etc) and Perl Regular Expressions which might work for you. It also might be that a simple LIKE or CONTAINS operator might work for you.

For example, this PROC PRINT shows the use of a WHERE clause using the LIKE operator. With the LIKE operator, the underscore (_) is a wildcard for one character and the percent sign (%) is a wildcard for more than one character.

 

See "Syntax of WHERE Expression" in the SAS documentation.

cynthia

data words;
    infile datalines;
    input vqueue $;
    return;
    datalines;
CTXYZ
XYZ.CT
ABCTG
RS.CT
;
run;

proc print data=words;
    where VQueue like '%.CT';
    title 'Search for %.CT - where % represents any characters before .CT';
run;

proc print data=words;
    title 'Search for __XYZ -- 2 underscores represent any 2 characters before XYZ';
    where VQueue like '__XYZ';
run;



View solution in original post

5 REPLIES 5
Cynthia_sas
SAS Super FREQ

Hi:
SAS has a lot of string processing functions (such as FIND, FINDW, INDEX, INDEXC, etc) and Perl Regular Expressions which might work for you. It also might be that a simple LIKE or CONTAINS operator might work for you.

For example, this PROC PRINT shows the use of a WHERE clause using the LIKE operator. With the LIKE operator, the underscore (_) is a wildcard for one character and the percent sign (%) is a wildcard for more than one character.

 

See "Syntax of WHERE Expression" in the SAS documentation.

cynthia

data words;
    infile datalines;
    input vqueue $;
    return;
    datalines;
CTXYZ
XYZ.CT
ABCTG
RS.CT
;
run;

proc print data=words;
    where VQueue like '%.CT';
    title 'Search for %.CT - where % represents any characters before .CT';
run;

proc print data=words;
    title 'Search for __XYZ -- 2 underscores represent any 2 characters before XYZ';
    where VQueue like '__XYZ';
run;



fredbell
Fluorite | Level 6
Thank you, i went with the Contains and it worked out.

Fred
art297
Opal | Level 21
Fred,

Since you had indicated that you wanted strings that "ended with "CT", I would have gone with Cynthia's suggestion to use the LIKE operator.

Art
RohitV
Calcite | Level 5

How can we use Wild Characters in Data Step?

I am trying to get something like.

data Apple;

Set Ball;

where upcase(trim(Column2)) like '%CAR%';

run;

But i got an error for this.

Is there any way to use this in Datastep?

Ksharp
Super User

data Apple;

Set Ball;

if find(upcase(trim(Column2)) , 'CAR' ) ;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 51065 views
  • 1 like
  • 5 in conversation