<?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 Detect if Excel file for import has blank first row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811710#M320183</link>
    <description>&lt;P&gt;I have an excel sheet that is sometimes sent to me with a blank first row (2nd row with column names) and other times with a normal format of the first row having the column names. These are the only two ways the file is provided to me (for now, this vendor loves to surprise me). I need this report to remain automated, so I would like to find a way to detect if the first row is blank and if it is then use the proc import range option to correctly start at row two for the column names. If the first row contains the column names then run normally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just cannot work out a tidy way of detecting if the first row is blank, I was considering using %IF and &lt;SPAN class=""&gt;%DATATYP&lt;/SPAN&gt;E macros, but I haven't tried to do something quite like this before in SAS and not finding something similar enough to adapt for my uses. I'm sure I'm overthinking this too. I would be grateful for any suggestions!&lt;/P&gt;</description>
    <pubDate>Thu, 05 May 2022 17:48:05 GMT</pubDate>
    <dc:creator>imead</dc:creator>
    <dc:date>2022-05-05T17:48:05Z</dc:date>
    <item>
      <title>Detect if Excel file for import has blank first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811710#M320183</link>
      <description>&lt;P&gt;I have an excel sheet that is sometimes sent to me with a blank first row (2nd row with column names) and other times with a normal format of the first row having the column names. These are the only two ways the file is provided to me (for now, this vendor loves to surprise me). I need this report to remain automated, so I would like to find a way to detect if the first row is blank and if it is then use the proc import range option to correctly start at row two for the column names. If the first row contains the column names then run normally.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just cannot work out a tidy way of detecting if the first row is blank, I was considering using %IF and &lt;SPAN class=""&gt;%DATATYP&lt;/SPAN&gt;E macros, but I haven't tried to do something quite like this before in SAS and not finding something similar enough to adapt for my uses. I'm sure I'm overthinking this too. I would be grateful for any suggestions!&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 17:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811710#M320183</guid>
      <dc:creator>imead</dc:creator>
      <dc:date>2022-05-05T17:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Detect if Excel file for import has blank first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811713#M320184</link>
      <description>&lt;P&gt;Can you be more specific about the type of "sheet" you are receiving.&lt;/P&gt;
&lt;P&gt;Is it an XLSX workbook?&amp;nbsp; Or an XLS workbook?&amp;nbsp; &amp;nbsp;If one of these does it contain multiple sheets or just on sheet?&lt;/P&gt;
&lt;P&gt;Or are perhaps getting a CSV file, which is not an Excel file but instead is just a text file.&lt;/P&gt;
&lt;P&gt;Other than the extra row does the file change its structure?&amp;nbsp; That is does it always have the same number of columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is an Excel file then you will have to IMPORT the file first before you can detect if there are any issues.&lt;/P&gt;
&lt;P&gt;You could easily use the RANGE option as you say to import just the first cell and then test if that is cell is empty or not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import out=test replace dbms=xlsx datafile='test.xlsx' replace;
  getnames=NO;
  range='$A1:A1';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now use that to define the RANGE to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set test ;
  put A=;
  call symputx('range',cats('$A',1+(A=' '),':'));
run;

%put &amp;amp;=range;

proc import out=want replace dbms=xlsx datafile='test.xlsx' replace;
  getnames=YES;
  range="&amp;amp;range";
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 18:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811713#M320184</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-05T18:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Detect if Excel file for import has blank first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811729#M320195</link>
      <description>&lt;P&gt;I am so sorry I should have specified .xls. I always forget some kind of relevant information.&lt;/P&gt;&lt;P&gt;Your solution works beautifully! Thank you very much.&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 18:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detect-if-Excel-file-for-import-has-blank-first-row/m-p/811729#M320195</guid>
      <dc:creator>imead</dc:creator>
      <dc:date>2022-05-05T18:58:26Z</dc:date>
    </item>
  </channel>
</rss>

