<?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: sas code for csv file validation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915821#M40986</link>
    <description>&lt;P&gt;None of those SCAN() function calls are going to return anything.&amp;nbsp; Your filename does not have any commas in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you want to look at the content of the line being read instead of the name of the file being read?&amp;nbsp; If so then use the automatic _INFILE_ variable instead of the variable you created with the FILENAME= option of the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is working WAAAAY too hard.&amp;nbsp; Let the INPUT statement parse the line.&amp;nbsp; You seem to want to ignore the first and fourth values on the line.&amp;nbsp; So just read them into a dummy character variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data 
   cleandata(keep= APP_ID SN_NUMBER SN_AMOUNT P_ID)
   errors(keep=Err_Message Faulty_Record)
;
   length APP_ID $255 SN_NUMBER SN_AMOUNT P_ID 8 Err_Message $100 Faulty_Record $250 ;
   infile "/home/sas/score.csv"
      filename = _filename 
      dsd
      truncover
      lrecl=32767
      firstobs=2
   ;
   length dummy $1 ;
   input dummy APP_ID SN_NUMBER ??
         dummy SN_AMOUNT ?? P_ID ?? 
   ;
   Faulty_Record = _INFILE_ ;

   if missing(APP_ID) then do;
      Err_Message = 'APP_ID variable cannot be missing';
      output work.errors; 
   end;
   if missing(SN_NUMBER) then do;
      Err_Message = 'SN_NUMBER variable cannot be missing';
      output work.errors; 
   end;
   if missing(P_ID) then do;
      Err_Message = 'P_ID variable cannot be missing';
      output work.errors; 
   end;
   if missing(Err_Message) then do;
      output work.cleandata;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2024 18:10:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-13T18:10:33Z</dc:date>
    <item>
      <title>sas code for csv file validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915625#M40973</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for a SAS code for validating a csv file.&lt;/P&gt;&lt;P&gt;I have variables like&amp;nbsp;&lt;/P&gt;&lt;P&gt;FORMAT STARTED_TS MDYAMPM.;&lt;BR /&gt;format yearmonth 8.;&lt;BR /&gt;format APP_ID $255.;&lt;BR /&gt;format SN_NUMBER 22.;&lt;BR /&gt;format SN_AMOUNT 20.2;&lt;BR /&gt;format P_ID 19.;&lt;/P&gt;&lt;P&gt;Want to keep all exceptional records in a separate dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kajal&lt;/P&gt;&lt;P&gt;I tried code but didn't work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data work.cleandata(keep= APP_ID SN_NUMBER SN_AMOUNT P_ID)
   work.errors(keep=Err_Message Faulty_Record)
;
   length 
      APP_ID $255 SN_NUMBER 8 SN_AMOUNT 8 P_ID 8 Err_Message $ 100 Faulty_Record $ 250 ;
   infile "/home/sas/score.csv " filename = _filename 
		delimiter = ","  
		dsd
		truncover
		missover dsd 
		lrecl=32767
		firstobs=2;
   input;
   APP_ID = scan(_filename,2, ',');
   SN_NUMBER = input(scan(_filename,3, ','), ?? best.);
   SN_AMOUNT = input(scan(_filename,5, ','), ?? best.);
   P_ID = input(scan(_filename,6, ','), ?? best.);

   if missing(APP_ID) then do;
      Faulty_Record = _filename;
      Err_Message = 'APP_ID variable cannot be missing';
      output work.errors; 
   end;
   if missing(SN_NUMBER) then do;
      Faulty_Record = _filename;
      Err_Message = 'SN_NUMBER variable cannot be missing';
      output work.errors; 
   end;
   if missing(P_ID) then do;
      Faulty_Record = _filename;
      Err_Message = 'P_ID variable cannot be missing';
      output work.errors; 
   end;

   if missing(Faulty_Record) then do;
      output work.cleandata;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 17:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915625#M40973</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-02-12T17:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: sas code for csv file validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915797#M40981</link>
      <description>&lt;P&gt;Replace _filename in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   APP_ID = scan(_filename,2, ',');
   SN_NUMBER = input(scan(_filename,3, ','), ?? best.);
   SN_AMOUNT = input(scan(_filename,5, ','), ?? best.);
   P_ID = input(scan(_filename,6, ','), ?? best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;by _infile_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 11:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915797#M40981</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-02-13T11:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: sas code for csv file validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915801#M40983</link>
      <description>&lt;P&gt;Never (as in&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;NEVER&lt;/STRONG&gt;&lt;/U&gt;) just say "it does not work" without giving further information.&lt;/P&gt;
&lt;P&gt;Post the complete (only remove multiple repeats of the same message) log and (if the step ran at all) show where the result does not meet your expectation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does your file really have that extra blank in the name?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 12:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915801#M40983</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-13T12:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: sas code for csv file validation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915821#M40986</link>
      <description>&lt;P&gt;None of those SCAN() function calls are going to return anything.&amp;nbsp; Your filename does not have any commas in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you want to look at the content of the line being read instead of the name of the file being read?&amp;nbsp; If so then use the automatic _INFILE_ variable instead of the variable you created with the FILENAME= option of the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code is working WAAAAY too hard.&amp;nbsp; Let the INPUT statement parse the line.&amp;nbsp; You seem to want to ignore the first and fourth values on the line.&amp;nbsp; So just read them into a dummy character variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data 
   cleandata(keep= APP_ID SN_NUMBER SN_AMOUNT P_ID)
   errors(keep=Err_Message Faulty_Record)
;
   length APP_ID $255 SN_NUMBER SN_AMOUNT P_ID 8 Err_Message $100 Faulty_Record $250 ;
   infile "/home/sas/score.csv"
      filename = _filename 
      dsd
      truncover
      lrecl=32767
      firstobs=2
   ;
   length dummy $1 ;
   input dummy APP_ID SN_NUMBER ??
         dummy SN_AMOUNT ?? P_ID ?? 
   ;
   Faulty_Record = _INFILE_ ;

   if missing(APP_ID) then do;
      Err_Message = 'APP_ID variable cannot be missing';
      output work.errors; 
   end;
   if missing(SN_NUMBER) then do;
      Err_Message = 'SN_NUMBER variable cannot be missing';
      output work.errors; 
   end;
   if missing(P_ID) then do;
      Err_Message = 'P_ID variable cannot be missing';
      output work.errors; 
   end;
   if missing(Err_Message) then do;
      output work.cleandata;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 18:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/sas-code-for-csv-file-validation/m-p/915821#M40986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-13T18:10:33Z</dc:date>
    </item>
  </channel>
</rss>

