<?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: Can someone please help me understand this macro step by step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279154#M56227</link>
    <description>&lt;P&gt;There's too much to explain.&amp;nbsp; You will need to study SAS language first, then macro language, to come up to speed on these questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This might help.&amp;nbsp; First, appreciate that there is an earlier piece missing here.&amp;nbsp; Somehow &amp;amp;FPATH got defined and assigned a value.&amp;nbsp; Whatever its value is, the value gets substituted into the program where &amp;amp;FPATH appears.&amp;nbsp; When this macro runs, it generates the following SAS code (again, with &amp;amp;FPATH replaced):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc import out= hand_Intake_paper datafile= "&amp;amp;fpath\Hand_Wrist.xlsx"&lt;/P&gt;
&lt;P&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;sheet = "Intake";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data = hand_Intake_paper;&lt;BR /&gt;by client_id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc import out= hand_Discharge_paper datafile= "&amp;amp;fpath\Hand_Wrist.xlsx"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;sheet = "Discharge";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data = hand_Discharge_paper;&lt;BR /&gt;by client_id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So &amp;amp;var1 and &amp;amp;var2 are being used ... think of them as replacing &amp;amp;&amp;amp;var&amp;amp;k when the macro runs.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jun 2016 20:39:35 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-06-21T20:39:35Z</dc:date>
    <item>
      <title>Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279144#M56225</link>
      <description>&lt;P&gt;Can someone please help me understand this macro step by step? I'm very new to sas so i'm having a hard time understanding macros.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro handimp;&lt;/P&gt;&lt;P&gt;%let var1 = Intake;&lt;BR /&gt;%let var2 = Discharge;&lt;/P&gt;&lt;P&gt;%do k=1 %to 2;&lt;/P&gt;&lt;P&gt;proc import out= hand_&amp;amp;&amp;amp;var&amp;amp;k.._paper datafile= "&amp;amp;fpath\Hand_Wrist.xlsx"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;sheet = "&amp;amp;&amp;amp;var&amp;amp;k";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = hand_&amp;amp;&amp;amp;var&amp;amp;k.._paper;&lt;BR /&gt;by client_id;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%handimp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Questions&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Why is this macro creating two macro variables called var1 and var2? Is this necessary? Is this meant to highlight the two sheets in my excel that I want to import?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. What does the following line mean exactly:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%do k=1 %to 2;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you! If you answer can you please answer simply as I don't always understand all the terminilogy just yet!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 20:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279144#M56225</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-21T20:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279154#M56227</link>
      <description>&lt;P&gt;There's too much to explain.&amp;nbsp; You will need to study SAS language first, then macro language, to come up to speed on these questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This might help.&amp;nbsp; First, appreciate that there is an earlier piece missing here.&amp;nbsp; Somehow &amp;amp;FPATH got defined and assigned a value.&amp;nbsp; Whatever its value is, the value gets substituted into the program where &amp;amp;FPATH appears.&amp;nbsp; When this macro runs, it generates the following SAS code (again, with &amp;amp;FPATH replaced):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc import out= hand_Intake_paper datafile= "&amp;amp;fpath\Hand_Wrist.xlsx"&lt;/P&gt;
&lt;P&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;sheet = "Intake";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data = hand_Intake_paper;&lt;BR /&gt;by client_id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc import out= hand_Discharge_paper datafile= "&amp;amp;fpath\Hand_Wrist.xlsx"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;sheet = "Discharge";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data = hand_Discharge_paper;&lt;BR /&gt;by client_id;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So &amp;amp;var1 and &amp;amp;var2 are being used ... think of them as replacing &amp;amp;&amp;amp;var&amp;amp;k when the macro runs.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 20:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279154#M56227</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-21T20:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279169#M56232</link>
      <description>&lt;P&gt;What are you trying to use this macro for? Is it something in code your working with or code your trying to adapt to something else?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2016 22:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279169#M56232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-21T22:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279838#M56440</link>
      <description>&lt;P&gt;I'm actually working with someone else's sas code and need to double check things for them. But also I'm just trying to learn it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for right now I think I just need someone to explain what the bolded part in the code means. I've googled it but it doens't make a lot of sense to me in plain english.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone explain that bolded section for me in general terms? Just so I have a high level understanding of what it is actually doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279838#M56440</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-23T20:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279840#M56441</link>
      <description>&lt;P&gt;It's a do loop start.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will loop from start of do loop to the %end statement each time incrementing&amp;nbsp;the value of k.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279840#M56441</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-23T20:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279844#M56444</link>
      <description>&lt;P&gt;s does the do loop say start at k, and k being observation 1...what does the 2 mean? Does that just mean it's going to the next observation? so 1, 2, 3 etc?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279844#M56444</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-23T20:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279856#M56449</link>
      <description>&lt;P&gt;It's a do loop...the start from - up to - end value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Loop from 1 to 2 in this case.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could easily be 1 to 20 if you wanted 20 loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And no, not observation are not being looped. This loops the entire procedure or portion of text.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write the out the entire piece of code and replace each instance of k with a 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then write out entire piece of code and replace each instance of k with a 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will show you what the code is doing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If running the code you can use the following to have the log display the details from each iteration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Option MPRINT SYMBOLGEN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 20:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279856#M56449</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-23T20:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279980#M56515</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 13:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279980#M56515</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-24T13:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone please help me understand this macro step by step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279986#M56516</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro handimp; /* Declares a macro function named handimp */

    %let var1 = Intake;     /* declares a macrovariable var1 that takes the value "Intake" (wo quotes) */
    %let var2 = Discharge;  /* declares a macrovariable var2 that takes the value "Discharge" (wo quotes) */

    %do k=1 %to 2; /* Loops on k from 1 to 2 */

        /* Imports data from an excel file, the name of which depends on k */
        proc import out= hand_&amp;amp;&amp;amp;var&amp;amp;k.._paper  /* &amp;amp;&amp;amp;var&amp;amp;k. first, Intake then Discharge */
                                               /* var&amp;amp;k =&amp;gt; var1 or var2 | &amp;amp;&amp;amp;var&amp;amp;k =&amp;gt; &amp;amp;var1 or &amp;amp;var2 */
            datafile= "&amp;amp;fpath\Hand_Wrist.xlsx" /* macrovariable fpath should be initialized somewhere else */
            dbms=xlsx replace;
            getnames=yes;
            sheet = "&amp;amp;&amp;amp;var&amp;amp;k";
        run;

        /* Sorts the newly created SAS dataset by client_id */
        proc sort data = hand_&amp;amp;&amp;amp;var&amp;amp;k.._paper;
            by client_id;
        run;
    %end; /* End of loop */

%mend; /* End of macro definition */

%handimp; /* Calls the macro handimp */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 13:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-someone-please-help-me-understand-this-macro-step-by-step/m-p/279986#M56516</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-06-24T13:50:32Z</dc:date>
    </item>
  </channel>
</rss>

