<?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: &amp;quot;Sanity&amp;quot; check for dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-Sanity-quot-check-for-dataset/m-p/639881#M190429</link>
    <description>&lt;P&gt;This is the sort of thing that I would delegate to my program that reads the data.&lt;/P&gt;
&lt;P&gt;Just how do you read the file into SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't have to do do more than indicate that there are not 15 fields then perhaps what might work better would be to read the number of columns that exist in the data set. SAS has, accessible in Proc SQL, DICTIONARY.COLUMNS that has the name and properties of every variable in every data set in all of the currently defined libraries. So you could look for the existence of specific variables with something similar to:&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table set1count as
   select count(*) 
   from dictionary.columns 
   where libname='WORK' and memname='DATASET1'
      and upcase(name) in ('FIELD1' 'FIELD2' 'FIELD3' ...)
   ;
run;&lt;/PRE&gt;
&lt;P&gt;library name and member name (data set name) are stored in upper case in the table. Name of variable is not so it may be a good idea to make sure your comparison is not case sensitive. The count would indicate how many of the variables in the list (I only did 3 out of laziness) were found. There are a number of ways to capture the information and use it. If paranoid enough you could check DICTIONARY.TABLES that MEMNAME exists as well.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Apr 2020 20:08:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-14T20:08:56Z</dc:date>
    <item>
      <title>"Sanity" check for dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sanity-quot-check-for-dataset/m-p/639872#M190426</link>
      <description>&lt;P&gt;&lt;FONT color="#000080"&gt;Receiving datasets from a variety of clients on a Redhat Enterprise Server 7 (Maipo)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;Need to check if the required 15 fields are present in the dataset, if not&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;then send message back to calling BASH program that the dataset submitted doesn't&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;"pass muster", so to speak.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;No further error handling is required, such as what fields are missing,etc,&amp;nbsp; at this point.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;Using simple create table proc sql to create a tmp dataset consisting of&amp;nbsp; fields 1 - 15 from the submitted dataset.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;If any one field of the fifteen is missing, PROC SQL throws an error,(obviously), although the&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;NOERRORSTOP optiion will allow the code to continue to execute, (to check any other datasets submitted along with the first one).&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;My boss REALLY doesn't want any errors in the log, even if I'm later checking to see if&amp;nbsp; tmp datasets 1,2,3, etc. exist.&amp;nbsp; If&amp;nbsp; just one of the tmp tables weren't created by the proc sql create query, the code sends an error message back to be collected by the BASH shell script.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;I'm thinking PROC SQL is not the answer to determine if a dataset has a full complement of variables (but not what is IN the variables).&amp;nbsp; If more variables are in the dataset than required, they will NOT be included, they just drop into the ether.&amp;nbsp; How else can I check multiple datasets for a full complement of variables?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;Code is really simple - &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Proc SQL;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;create table DS1 as select&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;field1 field2, field3,(etc).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;from dataset;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif" size="5" color="#000080"&gt;THANX.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 19:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sanity-quot-check-for-dataset/m-p/639872#M190426</guid>
      <dc:creator>Jumboshrimps</dc:creator>
      <dc:date>2020-04-14T19:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: "Sanity" check for dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Sanity-quot-check-for-dataset/m-p/639881#M190429</link>
      <description>&lt;P&gt;This is the sort of thing that I would delegate to my program that reads the data.&lt;/P&gt;
&lt;P&gt;Just how do you read the file into SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't have to do do more than indicate that there are not 15 fields then perhaps what might work better would be to read the number of columns that exist in the data set. SAS has, accessible in Proc SQL, DICTIONARY.COLUMNS that has the name and properties of every variable in every data set in all of the currently defined libraries. So you could look for the existence of specific variables with something similar to:&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table set1count as
   select count(*) 
   from dictionary.columns 
   where libname='WORK' and memname='DATASET1'
      and upcase(name) in ('FIELD1' 'FIELD2' 'FIELD3' ...)
   ;
run;&lt;/PRE&gt;
&lt;P&gt;library name and member name (data set name) are stored in upper case in the table. Name of variable is not so it may be a good idea to make sure your comparison is not case sensitive. The count would indicate how many of the variables in the list (I only did 3 out of laziness) were found. There are a number of ways to capture the information and use it. If paranoid enough you could check DICTIONARY.TABLES that MEMNAME exists as well.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 20:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Sanity-quot-check-for-dataset/m-p/639881#M190429</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-14T20:08:56Z</dc:date>
    </item>
  </channel>
</rss>

