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

I want to use Proc SQL to find out if there are any data in the column with Vertical Tab, Line Feed, Horizontal Tab, Carraige Return.

 

When running in Teradata directly i use the below query

 

SyntaxEditor Code Snippet

INDEX(Last_Nm, '09'XC ) > 0 -- Horizaontal tabOR INDEX(Last_Nm, '0A'XC ) > 0 -- Line FeedOR INDEX(Last_Nm, '0B'XC ) > 0 -- Vertical tabOR INDEX(Last_Nm, '0D'XC ) > 0 -- Carrriage Return

I used the below conditions in SAS EG inside a Proc SQL and it does not work.

(index(Frst_Nm,'09'x) >0) /*Horizontal Tab*/
Or index(Frst_Nm, '0A'x) > 0 /* Line Feed*/
Or index(Frst_Nm, '0B'x) > 0 /*Vertical tab*/
Or index(Frst_Nm, '0D'x) > 0 /*Carrriage Return*/
)

 

Are there any other ways? 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Function anycntrl detects control characters:

 

proc sql;
select *, anycntrl(Frst_nm) > 0 as flag
 from have;
quit;
PG

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

You have an extra parenthesis in your first use of the index function. The following worked for me:

 

data Have;
  length Frst_Nm $30.;
  i=1;
  Frst_Nm=catt('John','09'x,'Junk');
  output;
  i=2;
  Frst_Nm=catt('John','0A'x,'Junk');
  output;
  i=3;
  Frst_Nm=catt('John','0B'x,'Junk');
  output;
  i=4;
  Frst_Nm=catt('John','0D'x,'Junk');
  output;
  i=5;
  Frst_Nm=catt('John','Junk');
  output;
run;

proc sql;
  select *,
  (index(Frst_Nm,'09'x) >0 /*Horizontal Tab*/
    Or index(Frst_Nm, '0A'x) > 0 /* Line Feed*/
    Or index(Frst_Nm, '0B'x) > 0 /*Vertical tab*/
    Or index(Frst_Nm, '0D'x) > 0 /*Carrriage Return*/
  ) as test
    from have
  ;
quit;

Art, CEO, AnalystFinder.com

JM_VFAU
Obsidian | Level 7

I may have put an extra bracket when typing up the post. I am using this code in the SAS CI as an exclusion list. but it seems to be working sometimes but not when the campaign is scheduled.

Ksharp
Super User
It is easy for Perl Regular Expression.


data Have;
  length Frst_Nm $30.;
  i=1;
  Frst_Nm=catt('John','09'x,'Junk');
  output;
  i=2;
  Frst_Nm=catt('John','0A'x,'Junk');
  output;
  i=3;
  Frst_Nm=catt('John','0B'x,'Junk');
  output;
  i=4;
  Frst_Nm=catt('John','0D'x,'Junk');
  output;
  i=5;
  Frst_Nm=catx(' ','John','Junk');
  output;
run;
proc sql;
select *,case when prxmatch('/\s/',compress(frst_nm,' ')) then 1 else 0 end as flag
 from have;
quit;

JM_VFAU
Obsidian | Level 7

Thanks. I will try this option.

PGStats
Opal | Level 21

Function anycntrl detects control characters:

 

proc sql;
select *, anycntrl(Frst_nm) > 0 as flag
 from have;
quit;
PG

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!

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