<?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: Nesting a macro within another macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77416#M16719</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Astounding said ,add another parameter to identify a dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro var(dsn,sec);&lt;/P&gt;&lt;P&gt;data &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if &amp;amp;sec not = "" then tot_&amp;amp;sec + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ptstid cycle;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.cycle and &amp;amp;sec = 1 then tot_&amp;amp;sec = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%MEND var;&lt;/P&gt;&lt;P&gt;options mprint;&lt;/P&gt;&lt;P&gt;%var(f,gm_hold)&lt;/P&gt;&lt;P&gt;%var(g,gm_red)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Apr 2012 06:17:27 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-04-11T06:17:27Z</dc:date>
    <item>
      <title>Nesting a macro within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77412#M16715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have this macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro var(sec);&lt;/P&gt;&lt;P&gt;data f;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set f;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if &amp;amp;sec not = "" then tot_&amp;amp;sec + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ptstid cycle;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.cycle and &amp;amp;sec = 1 then tot_&amp;amp;sec = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%MEND var;&lt;/P&gt;&lt;P&gt;options mprint;&lt;/P&gt;&lt;P&gt;%var(gm_hold)&lt;/P&gt;&lt;P&gt;%var(gm_red)&lt;/P&gt;&lt;P&gt;%var(cis_hold)&lt;/P&gt;&lt;P&gt;%var(cis_red)&lt;/P&gt;&lt;P&gt;%var(cet_hold)&lt;/P&gt;&lt;P&gt;%var(cet_red)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro as currently written is working on dataset "f". However, I have 4 different datasets that I need to run this same macro on (f,g,h,i). How would I write a macro that would do this. Essentially I am trying to do a macro inside of a macro. Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2012 16:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77412#M16715</guid>
      <dc:creator>cypher85</dc:creator>
      <dc:date>2012-04-10T16:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting a macro within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77413#M16716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Do you want to try if this one works?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; dsn=f g h i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; var=gm_hold gm_red cis_hold cis_red cet_hold cet_red;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; var();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; i=&lt;/SPAN&gt;&lt;SPAN style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%to&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;(countw(&amp;amp;dsn));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; ndsn=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;(scan(&amp;amp;dsn,&amp;amp;i));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; j=&lt;/SPAN&gt;&lt;SPAN style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%to&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;(countw(&amp;amp;var));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; nvar=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;(scan(&amp;amp;var,&amp;amp;j));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data &amp;amp;ndsn._&amp;amp;nvar;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;ndsn;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if &amp;amp;nvar ne &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 12pt;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; then tot_&amp;amp;nvar+&lt;/SPAN&gt;&lt;SPAN style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by ptstid cycle;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.cycle and &amp;amp;nvar = &lt;/SPAN&gt;&lt;SPAN style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; then tot_&amp;amp;nval = &lt;/SPAN&gt;&lt;SPAN style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; var;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;options&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;mprint&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;var&lt;/EM&gt;&lt;/STRONG&gt;()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;Linlin&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2012 17:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77413#M16716</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-10T17:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting a macro within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77414#M16717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wouldn't recommend nesting macros within macros.&amp;nbsp; One alternative might be to call the macro, using call execute from a data step.&amp;nbsp; That way, you could either list all of your desired files within the datastep, or use a pipe to identify the files.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2012 17:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77414#M16717</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-04-10T17:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting a macro within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77415#M16718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;cypher85,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You would be better served, and learn more, if you took this in steps.&amp;nbsp; Each of these steps will force you to learn something.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, without the use of any macro language, how could a single DATA step process all 6 variables?&amp;nbsp; Remember, each DATA step has to input and output all the observations.&amp;nbsp; If you can use one DATA step instead of six, your programs will run considerably faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second, how could you do this in macro language?&amp;nbsp; Using just one data set, pass a list of variable names instead of just one.&amp;nbsp; Have the macro use that list of variable names to construct the program that you came up with in step 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, how could you add a second parameter to the macro that contains a list of data set names.&amp;nbsp; Have the macro run through the same process for each data set in the list.&amp;nbsp; This is the least important step on the list.&amp;nbsp; Your program would be easier to write, and easier to understand, if you were to forget about this step and just run the macro separately for each of your four data sets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2012 19:15:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77415#M16718</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-04-10T19:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Nesting a macro within another macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77416#M16719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Astounding said ,add another parameter to identify a dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro var(dsn,sec);&lt;/P&gt;&lt;P&gt;data &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set &amp;amp;dsn;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if &amp;amp;sec not = "" then tot_&amp;amp;sec + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ptstid cycle;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.cycle and &amp;amp;sec = 1 then tot_&amp;amp;sec = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%MEND var;&lt;/P&gt;&lt;P&gt;options mprint;&lt;/P&gt;&lt;P&gt;%var(f,gm_hold)&lt;/P&gt;&lt;P&gt;%var(g,gm_red)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Apr 2012 06:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nesting-a-macro-within-another-macro/m-p/77416#M16719</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-04-11T06:17:27Z</dc:date>
    </item>
  </channel>
</rss>

