<?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: MACRO Data import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865599#M341839</link>
    <description>&lt;P&gt;Whenever you have an ERROR, we&amp;nbsp;&lt;U&gt;must&lt;/U&gt; see your log. Post the complete (all code and messages) by copy/pasting it into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2023 20:47:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-03-21T20:47:40Z</dc:date>
    <item>
      <title>MACRO Data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865595#M341835</link>
      <description>&lt;P&gt;Hi there- puzzled with the macro I frequently use w/o any issues.&lt;/P&gt;&lt;P&gt;Anything you catch that is causing err? I have multiple sheets in a spreadsheet and want to import them. This is a really simple task.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Let&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;dir =C:\Users\myproject\;&lt;/P&gt;&lt;P&gt;%let&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;data_in= clinsub;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;clin_sub(sheet);&lt;/P&gt;&lt;P&gt;Proc import&lt;/P&gt;&lt;P&gt;DATAFILE =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;"&amp;amp;dir.clinsub"&lt;/P&gt;&lt;P&gt;DBMS = xlsx&lt;/P&gt;&lt;P&gt;OUT = clinsub&amp;nbsp; REPLACE;&lt;/P&gt;&lt;P&gt;SHEET ="&amp;amp;sheet";&lt;/P&gt;&lt;P&gt;GETNAMES = YES&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;clin_sub;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 20:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865595#M341835</guid>
      <dc:creator>emelergul</dc:creator>
      <dc:date>2023-03-21T20:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865599#M341839</link>
      <description>&lt;P&gt;Whenever you have an ERROR, we&amp;nbsp;&lt;U&gt;must&lt;/U&gt; see your log. Post the complete (all code and messages) by copy/pasting it into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 20:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865599#M341839</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-21T20:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865614#M341842</link>
      <description>&lt;P&gt;The code you posted does nothing since it only defines the macro and does not call the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro has some coding issues:&lt;/P&gt;
&lt;P&gt;There is no semicolon to end the GETNAMES statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro has some logic issues.&lt;/P&gt;
&lt;P&gt;It always creates the same output dataset.&amp;nbsp; So if you call it multiple times only the result of the last call will be available.&lt;/P&gt;
&lt;P&gt;It uses a "magic" macro variable.&amp;nbsp; In the middle of the macro you reference the macro variable named DIR which is not an input to the macro.&amp;nbsp; So the macro is just assuming the macro variable DIR will appear as if by magic out of thin air.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps you wanted a macro like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_xlsx
(sheet
,file
,dataset
,dir=C:\Users\myproject\
);

proc import
  DATAFILE = "&amp;amp;dir.&amp;amp;file"
  DBMS = xlsx
  OUT = &amp;amp;dataset  REPLACE
;
  SHEET ="&amp;amp;sheet";
  GETNAMES = YES;
RUN;
%mend import_xlsx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you could then call multiple times:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%import_xlxs(file=clinsub.xlsx,sheet=sheet1,dataset=first);
%import_xlxs(dataset=second,file=clinsub.xlsx,sheet=sheet2);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you want copy multiple sheets out of an XLSX file then just use the XLSX libname engine and skip the macro completely.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myxlsx xlsx "C:\Users\myproject\clinsub.xlsx";
proc copy inlib=myxlsx out=work;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2023 21:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-Data-import/m-p/865614#M341842</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-21T21:54:02Z</dc:date>
    </item>
  </channel>
</rss>

