<?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 validation check to capture the error record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593121#M170162</link>
    <description>&lt;P&gt;I might suggest incorporating the line number of the file read into the error record data set as well. Usually the automatic variable _n_ helps provide that.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 16:52:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-01T16:52:27Z</dc:date>
    <item>
      <title>Data validation check to capture the error record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593005#M170115</link>
      <description>&lt;P&gt;Assume I'm reading a .csv file to create one dataset. It has variables like ID,Sex and Age. Now I want to perform checks like ID cannot be missing, Sex should not be other than 'M' or 'F' and Age value should not be character. In case if the CSV file has data which doesn't comply with the above rules then I've to capture that record into another dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume I've the CSV file like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;ID&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;Sex&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;Age&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;M&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;21&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;.&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;F&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 23&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;M&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Arial" size="3"&gt;H&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above example, second and third record doesn't comply with the above said rules, so I want to capture those records&amp;nbsp;in&amp;nbsp;WANT dataset as follows. Data in faulty record should be seperated by spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Err_Message&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Faulty_Record&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID variable cannot be missing&lt;/TD&gt;&lt;TD&gt;. F 23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Age variable cannot be character&lt;/TD&gt;&lt;TD&gt;23&amp;nbsp;M H&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone provide me some guidance&amp;nbsp;on this exercise?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 12:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593005#M170115</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-10-01T12:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Data validation check to capture the error record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593033#M170125</link>
      <description>&lt;P&gt;Are you looking for a data set or a report? I'm pretty sure that SAS would import the age column as a character variable if it detects an "H" in it, so your second error message wouldn't occur. I imported a .csv with the same data and that's what happened--SAS imported the field as character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other than that, you can do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ sex $ age $;
datalines;
1 M 21
. F 23
23 M H
;
run;

data want;
set have;
if id = " " then do;
	err_message = "ID Variable cannot be missing";
end;
run;

proc print data=want;
where err_message ^= " ";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This obviously provides both a data set and a report.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 14:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593033#M170125</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2019-10-01T14:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Data validation check to capture the error record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593042#M170128</link>
      <description>&lt;P&gt;What should happen if a record has more than one error? The following code writes one obs for each error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename bob "%sysfunc(pathname(work))\test.csv";

data _null_;
   file bob;
   infile datalines;
   input;
   put _infile_;
   datalines;
ID,Sex,Age
1,M,21
.,F,23
23,M,H
;
run;


data work.cleandata(keep=Id Sex Age)
   work.errors(keep=Err_Message Faulty_Record)
;
   length 
      Id 8 Sex $ 1 Age 8
      Err_Message $ 100
      Faulty_Record $ 250
   ;

   infile bob firstobs=2;
   input;

   Id = input(scan(_infile_, 1, ','), ?? best.);
   Sex = scan(_infile_, 2, ',');
   Age = input(scan(_infile_, 3, ','), ?? best.);

   if missing(Id) then do;
      Faulty_Record = _infile_;
      Err_Message = 'ID variable cannot be missing';
      output work.errors; 
   end;

   if Sex not in ('M', 'F') then do;
      
   end;

   if missing(Age) then do;
      Faulty_Record = _infile_;
      Err_Message = 'Age is not numeric';
      output work.errors;
   end;

   if missing(Faulty_Record) then do;
      output work.cleandata;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 14:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593042#M170128</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-10-01T14:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Data validation check to capture the error record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593121#M170162</link>
      <description>&lt;P&gt;I might suggest incorporating the line number of the file read into the error record data set as well. Usually the automatic variable _n_ helps provide that.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-validation-check-to-capture-the-error-record/m-p/593121#M170162</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-01T16:52:27Z</dc:date>
    </item>
  </channel>
</rss>

