<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Transferring SQL code in SAS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950435#M42726</link>
    <description>&lt;P&gt;It would be better if you explained the rules you want to follow, rather than providing PRX code, which I am unfamiliar with.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2024 13:30:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-11-12T13:30:45Z</dc:date>
    <item>
      <title>Transferring SQL code in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950431#M42724</link>
      <description>&lt;P&gt;Good day I would like assistance in transforming this SQL code into a code suitable for SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to identify email addresses that do not conform to the validation rules set out for a valid email address.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CASE&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;WHEN [EMAIL_ADRES_X] LIKE '%_@__%.__%' AND PATINDEX('\b[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}\b', [EMAIL_ADRES_X]) = 0 THEN 1&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ELSE 0&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;END AS email_conformity&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;FROM #T2&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 12:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950431#M42724</guid>
      <dc:creator>AB1976</dc:creator>
      <dc:date>2024-11-12T12:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Transferring SQL code in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950432#M42725</link>
      <description>&lt;P&gt;I don't remember the syntax for the PRXMATCH function offhand, but you'd do something like this - just multiplying these two binary checks (&amp;gt;0 and =0) together to create a 0/1 variable called email_conformity.&amp;nbsp; Note that "email_address" is assumed to be a variable (column) in your input data and input data is called 'emailaddr':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data emailaddr;
set emailaddr;
email_conformity=(
    prxmatch(YOUR EMAIL REGEX, email_address)&amp;gt;0
    *
    prxmatch(YOUR OTHER REGEX, email_address)=0
    );
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Nov 2024 12:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950432#M42725</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-12T12:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Transferring SQL code in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950435#M42726</link>
      <description>&lt;P&gt;It would be better if you explained the rules you want to follow, rather than providing PRX code, which I am unfamiliar with.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 13:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950435#M42726</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-12T13:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Transferring SQL code in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950442#M42728</link>
      <description>&lt;P&gt;Are you asking how to translate the PATINDEX() function that is included as an SQL enhancement in your current SQL dialect into a SAS function?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try&amp;nbsp;PRXMATCH function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you asking what to do about those strange square brackets and hash mark?&amp;nbsp; For those I think you want to replace them with the actual names of your variables and dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 14:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950442#M42728</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-12T14:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Transferring SQL code in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950506#M42730</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/468362"&gt;@AB1976&lt;/a&gt;&amp;nbsp;Something like below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select 
  CASE 
  WHEN 
      EMAIL_ADRES_X LIKE '%_@__%.__%' 
      AND prxmatch('/\b[a-zA-Z0-9\._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}\b/i', strip(EMAIL_ADRES_X)) = 1 
      THEN 1
      ELSE 0
      END AS email_conformity
  FROM have
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Like SQL Server patindex() SAS prxmatch() will return the starting position of a match or zero if it isn't found.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the looks of it your RegEx got some "issues" - especially the full stop that's not masked and though stands for any character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of inventing a email validation RegEx yourself I'd Google for it. Below one way how you could modify your current syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  EMAIL_ADRES_X='firstname.lastname@somecompany.com'; output;
  EMAIL_ADRES_X='..@somecompany.com'; output;

run;

proc sql;
  select 
  CASE 
  WHEN 
    prxmatch('/^[a-z0-9][\w\.-]+@[\w\.-]+\.[a-z]{2,6}$/oi', strip(EMAIL_ADRES_X)) = 1 THEN 1
    ELSE 0
    END AS email_conformity
  FROM have
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 21:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transferring-SQL-code-in-SAS/m-p/950506#M42730</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-12T21:04:45Z</dc:date>
    </item>
  </channel>
</rss>

