<?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: Data Validity Check Using Another Table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861952#M340445</link>
    <description>&lt;P&gt;Thank you so much for the reply Patrick. This was exactly what I was looking for even though some of the logic was foreign to me. I really appreciate that you took the time to help! Have a great day!&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2023 14:21:55 GMT</pubDate>
    <dc:creator>can1112</dc:creator>
    <dc:date>2023-03-02T14:21:55Z</dc:date>
    <item>
      <title>Data Validity Check Using Another Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861659#M340352</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to do a validity check on table A by checking to see if the data matches values that are determined in table B. The table (B) has two columns, the variable name and values in a long form:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;datalines;
Client_Type 1
Client_Type 2
Client_Type 3
Client_Vendor 1
Client_Vendor 2
Client_Vendor 3
;&lt;/PRE&gt;&lt;P&gt;What is a good way to check that the same variable will conform to those values in table B? Since there are 200 variables, is there a way to create a macro to do this more efficiently?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your time!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 06:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861659#M340352</guid>
      <dc:creator>can1112</dc:creator>
      <dc:date>2023-03-01T06:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Data Validity Check Using Another Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861686#M340359</link>
      <description>&lt;P&gt;You will need to put in more work to make below really useful but it should give you the main idea how to approach this.&lt;/P&gt;
&lt;P&gt;You will likely need a separate lookup table for character and numerical columns and you will certainly need two hashes and two arrays. Below only for numerical columns.&lt;/P&gt;
&lt;P&gt;I normally create an error and an exception table in such cases. The error table stores all rows with a least one failed error, the exception table got a row per failed DQ check. Error and Exception table can be linked over source row number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
  infile datalines4 truncover;
  input __varname :$upcase32. __value :best32.;
  datalines;
Client_Type 1
Client_Type 2
Client_Type 3
Client_Vendor 1
Client_Vendor 2
Client_Vendor 3
;

data have;
  infile datalines4 truncover dsd;
  input client_type client_vendor;
datalines;
1,3
3,3
4,1
1,4
4,4
;

data comply fail;

  set have;
  array _nvars {*} _numeric_;

  if _n_=1 then
    do;
      if 0 then set lookup(keep=__varname __value);
      dcl hash h1(dataset:'lookup');
      h1.defineKey('__varname','__value');
      h1.defineDone();
    end;
  call missing(of __varname,__value);
  drop _:;

  do _i=1 to dim(_nvars);
    if h1.check(key:upcase(vname(_nvars[_i])),key:_nvars[_i]) ne 0 then 
      do;
        output fail;
        return;
      end;
  end;
  output comply;
run;

proc print data=comply;
run;
proc print data=fail;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1677660911892.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80983i5F59B2D6687A78FD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1677660911892.png" alt="Patrick_0-1677660911892.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 08:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861686#M340359</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-03-01T08:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Data Validity Check Using Another Table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861952#M340445</link>
      <description>&lt;P&gt;Thank you so much for the reply Patrick. This was exactly what I was looking for even though some of the logic was foreign to me. I really appreciate that you took the time to help! Have a great day!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 14:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Validity-Check-Using-Another-Table/m-p/861952#M340445</guid>
      <dc:creator>can1112</dc:creator>
      <dc:date>2023-03-02T14:21:55Z</dc:date>
    </item>
  </channel>
</rss>

