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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2903 views
  • 0 likes
  • 4 in conversation