<?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 for data import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674150#M202950</link>
    <description>&lt;P&gt;As I think about this problem, do you want to determine the current month, which as of today would be month 8, and then run the code for the current month? Or can the month number be any number at any time of the year (example, it is August but you want the February data)?&lt;/P&gt;</description>
    <pubDate>Mon, 03 Aug 2020 14:44:05 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-08-03T14:44:05Z</dc:date>
    <item>
      <title>Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674147#M202948</link>
      <description>&lt;P&gt;Hello, I'm trying to figure out how to automate this code so that I just need to change 1 number instead of copy and pasting code everytime I need to change it:&lt;/P&gt;
&lt;P&gt;Where there is a '1' or a '2', that's the number that changes&lt;/P&gt;
&lt;P&gt;*january;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;IMPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;OUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=pregnacy_referrals1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DATAFILE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"/windows/Pregnancy File 01.2020"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DBMS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=XLSX &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;REPLACE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;GETNAMES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=YES;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;SHEET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"DETAILS"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;*february;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;IMPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;OUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=pregnacy_referrals2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DATAFILE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"/windows/Pregnancy File 02.2020"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DBMS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=XLSX &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;REPLACE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;GETNAMES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=YES;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;SHEET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"DETAILS"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 14:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674147#M202948</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2020-08-03T14:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674150#M202950</link>
      <description>&lt;P&gt;As I think about this problem, do you want to determine the current month, which as of today would be month 8, and then run the code for the current month? Or can the month number be any number at any time of the year (example, it is August but you want the February data)?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 14:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674150#M202950</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-03T14:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674151#M202951</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261072"&gt;@jmmedina25&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I'm trying to figure out how to automate this code so that I just need to change 1 number instead of copy and pasting code everytime I need to change it:&lt;/P&gt;
&lt;P&gt;Where there is a '1' or a '2', that's the number that changes&lt;/P&gt;
&lt;P&gt;*january;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;IMPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;OUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=pregnacy_referrals1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DATAFILE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"/windows/Pregnancy File 01.2020"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DBMS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=XLSX &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;REPLACE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;GETNAMES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=YES;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;SHEET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"DETAILS"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;*february;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;IMPORT&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;OUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=pregnacy_referrals2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DATAFILE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"/windows/Pregnancy File 02.2020"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;DBMS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=XLSX &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;REPLACE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;GETNAMES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=YES;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;SHEET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;"DETAILS"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You probably want to rephrase your "Where there is a '1' or a '2', that's the number that changes"&lt;/P&gt;
&lt;P&gt;because you have multiple 2's as in 2020.&lt;/P&gt;
&lt;P&gt;And what about when 2021 rolls around??? You still have to change the 2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus you probably should consider naming your sets &lt;FONT face="Courier New" size="3"&gt;pregnacy_referrals01 instead of pregnacy_referrals1. Other wise you would need two macro variables that still need to both be changed and not save any thing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Consider:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;%let monthnum=01;

PROC IMPORT OUT=pregnacy_referrals&amp;amp;monthnum.
DATAFILE= "/windows/Pregnancy File &amp;amp;monthnum..2020"
DBMS=XLSX REPLACE;
GETNAMES=YES;
SHEET="DETAILS";
RUN;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;The 2 periods in is intentional and required. The macro processor uses . to indicate the end of a macro variable. If you use &amp;amp;monthnum.2020 the value would resolve to 012020, without a . and not be your file name. And if you were to use &amp;amp;monthnum2020 you would get an error that the macro variable monthnum2020 is undefined.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 14:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674151#M202951</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-03T14:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674167#M202958</link>
      <description>Okay, thanks.  Since I need the code to go through multiple months at one time, can I do %let monthnum=01, 02, 03, ect.?</description>
      <pubDate>Mon, 03 Aug 2020 15:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674167#M202958</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2020-08-03T15:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674168#M202959</link>
      <description>Ideally, it would iterate through the months starting at 01.2020 and ending on the current month 08.2020</description>
      <pubDate>Mon, 03 Aug 2020 15:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674168#M202959</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2020-08-03T15:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674169#M202960</link>
      <description>&lt;P&gt;No, because then your code would resolve to :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC IMPORT OUT=pregnacy_referrals01,02,03
DATAFILE= "/windows/Pregnancy File 01,02,03.2020"
DBMS=XLSX REPLACE;
GETNAMES=YES;
SHEET="DETAILS";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to pass a list of values, one way would be to write a macro with an iterative %DO loop that iterates over the list, and generates one PROC IMPORT step for each item of the list. There are also non-macro approaches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your subject asks about macro, have you tried the macro approach? If so, please share your macro, I'm sure folks will be happy to point out why it's not working.&amp;nbsp; While people might also just write the macro for you, IMHO you learn more when you share code that people can respond to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 16:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674169#M202960</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-08-03T16:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for data import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674176#M202965</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro iterate;
data _null_;
    call symputx('curr_month',month(today()));
    call symputx('year',year(today()));
run;
%do i=1 %to &amp;amp;curr_month;
    PROC IMPORT OUT=pregnacy_referrals_&amp;amp;year._%sysfunc(putn(&amp;amp;i,z2.))
        DATAFILE= "/windows/Pregnancy File %sysfunc(putn(&amp;amp;i,z2.)).&amp;amp;year"
    DBMS=XLSX REPLACE;
    GETNAMES=YES;
    SHEET="DETAILS";
    RUN;
%end;
%mend iterate;
%iterate
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As a suggestion for improvement, if people are naming Excel file as 01.2020, this will not sort in proper chronological order. If you name the Excel files as 2020.01, then these indeed will sort in proper chronological order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also as a fine point to help you obtain better answers more quickly, the concept of iteration was not mentioned in your original post, you probably would have been better off to say that specifically.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 17:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-data-import/m-p/674176#M202965</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-03T17:15:38Z</dc:date>
    </item>
  </channel>
</rss>

