<?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: passing string argument in a datastep from one macro to another macro in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253777#M13398</link>
    <description>&lt;P&gt;Thanks for the suggestion. You're right - I was passing the string "f2r" instead of the value of the variable.&lt;/P&gt;&lt;P&gt;But I had tried the syntax you suggested before I posted the question - it didn't work.&lt;/P&gt;&lt;P&gt;The problem seems to be in how the argument is interpreted in macro2 when it's passed from macro1. Is this an issue only BETWEEN macros? I don't know.&lt;/P&gt;&lt;P&gt;But this works. NOTE the " " around &amp;amp;prov in macro2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro macro1;&lt;BR /&gt;data _NULL_; set dset1;&lt;BR /&gt;call execute('%macro2('||trim(prov)||')');&lt;BR /&gt;run;&lt;BR /&gt;%mend macro1;&lt;BR /&gt;&lt;BR /&gt;%macro macro2(prov);&lt;BR /&gt;data dset2;&lt;/P&gt;&lt;P&gt;prov = "&amp;amp;prov";&lt;/P&gt;&lt;P&gt;f2r =&amp;nbsp;'c:\directoryname\'||prov||'_vol.dat';&lt;BR /&gt;infile dummy filevar = f2r&amp;nbsp;firstobs=2;&lt;BR /&gt;input name $ id_no ecoreg;&lt;BR /&gt;run;&lt;BR /&gt;* do some stuff with dset2;&lt;BR /&gt;%mend macro2;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2016 12:41:59 GMT</pubDate>
    <dc:creator>david_NRCan</dc:creator>
    <dc:date>2016-03-02T12:41:59Z</dc:date>
    <item>
      <title>passing string argument in a datastep from one macro to another macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253426#M13377</link>
      <description>&lt;P&gt;Hi SAS users,&lt;/P&gt;&lt;P&gt;I have a simple macro (macro1) that creates a dataset with n observations of 1 string variable.&lt;/P&gt;&lt;P&gt;I use the string variable to construct a file name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within a data step I want to pass the file name&amp;nbsp;to macro2 (n times), Macro2 uses the filename as an argument to open the appropriate file and&amp;nbsp;do some stuff.&lt;/P&gt;&lt;P&gt;But the filename is not being passed to macro2. Can someone tell me what I'm doing wrong? All help will be greatly appreciated.&lt;/P&gt;&lt;P&gt;SAS version 9.2&lt;/P&gt;&lt;P&gt;Win7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro macro1;&lt;/P&gt;&lt;P&gt;* do some stuff to create dset1 with n observations of 1 string variable ('prov');&lt;/P&gt;&lt;P&gt;* I have confirmed that dset1 exists, and that it has the correct string variable 'prov';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data _NULL_; set dset1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; f2r = 'c:\directoryname\'||trim(prov)||'_vol.dat';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call execute('%macro2(f2r)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;%mend macro1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro macro2(fname);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;data dset2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; infile dummy filevar = &amp;amp;fname firstobs=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; input name $ id_no ecoreg;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;* do some stuff with dset2;&lt;/P&gt;&lt;P&gt;%mend macro2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 13:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253426#M13377</guid>
      <dc:creator>david_NRCan</dc:creator>
      <dc:date>2016-03-01T13:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: passing string argument in a datastep from one macro to another macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253429#M13379</link>
      <description>&lt;P&gt;You're passing the characters "f2r" rather than the value of the DATA step variable.&amp;nbsp; Try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute('%macro2(' || f2r || ')');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 13:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253429#M13379</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-01T13:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: passing string argument in a datastep from one macro to another macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253450#M13380</link>
      <description>&lt;P&gt;Sorry, its not clear to me here. &amp;nbsp;You have code generation (the call execute), happening from within code generation (the macro). &amp;nbsp;This seems very convoluted. &amp;nbsp;Also, your call execute may not function as you expect it to, macro and call execute both insert code into the pre-processor, but they only do it once, so having one inside the other is not a good idea. &amp;nbsp;Explain your problem, provide example test data, and what you want out of it. &amp;nbsp;For instance why is macro1 needed, if that serves a purpose, separate it out from other processing. &amp;nbsp;The code you have posted seems to resolve to:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set dset1;
  call execute('data dset2; 
                  infile "c:\directoryname\'||strip(prov)||'_vol.dat;
                  input name $ id_no ecoreg;  
                run;');
run;&lt;/PRE&gt;
&lt;P&gt;So no need for all the other bits.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 14:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253450#M13380</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-01T14:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: passing string argument in a datastep from one macro to another macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253777#M13398</link>
      <description>&lt;P&gt;Thanks for the suggestion. You're right - I was passing the string "f2r" instead of the value of the variable.&lt;/P&gt;&lt;P&gt;But I had tried the syntax you suggested before I posted the question - it didn't work.&lt;/P&gt;&lt;P&gt;The problem seems to be in how the argument is interpreted in macro2 when it's passed from macro1. Is this an issue only BETWEEN macros? I don't know.&lt;/P&gt;&lt;P&gt;But this works. NOTE the " " around &amp;amp;prov in macro2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro macro1;&lt;BR /&gt;data _NULL_; set dset1;&lt;BR /&gt;call execute('%macro2('||trim(prov)||')');&lt;BR /&gt;run;&lt;BR /&gt;%mend macro1;&lt;BR /&gt;&lt;BR /&gt;%macro macro2(prov);&lt;BR /&gt;data dset2;&lt;/P&gt;&lt;P&gt;prov = "&amp;amp;prov";&lt;/P&gt;&lt;P&gt;f2r =&amp;nbsp;'c:\directoryname\'||prov||'_vol.dat';&lt;BR /&gt;infile dummy filevar = f2r&amp;nbsp;firstobs=2;&lt;BR /&gt;input name $ id_no ecoreg;&lt;BR /&gt;run;&lt;BR /&gt;* do some stuff with dset2;&lt;BR /&gt;%mend macro2;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 12:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253777#M13398</guid>
      <dc:creator>david_NRCan</dc:creator>
      <dc:date>2016-03-02T12:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: passing string argument in a datastep from one macro to another macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253786#M13399</link>
      <description>&lt;P&gt;Thank you for your reply. I'm sorry that it was not clear to you. I posted only what I thought was necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;macro1 is called several times; each time creating a different version of dset1 (different values of the pertinent variable 'prov').&lt;/P&gt;&lt;P&gt;macro2 is called as many times as there are observations in dset1, and creates a version of dset2 each time.&lt;/P&gt;&lt;P&gt;Calling a "function" from another "function" in other programming languages is not convoluted. Perhaps doing the same with SAS macros is uncommon.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 12:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253786#M13399</guid>
      <dc:creator>david_NRCan</dc:creator>
      <dc:date>2016-03-02T12:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: passing string argument in a datastep from one macro to another macro</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253792#M13400</link>
      <description>&lt;P&gt;Yes, first thing to remember is that SAS Macro is&amp;nbsp;&lt;STRONG&gt;not&lt;/STRONG&gt; like functions in other languages. &amp;nbsp;Macro language is a text generation software, i.e. it generates code, nothing else. &amp;nbsp;It is useful to avoid repeating code where only certain bits change. &amp;nbsp;It does this by passing macro logic to the pre-processor once, call execute is simlar. &amp;nbsp;As this only happens once, its not generally a good idea to be call execute generating data from inside a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I posted there is generally better ways of doing this. &amp;nbsp;If you can provide some test data and what you want the output to look like I can provide code, but the way it is now its messy and difficult to debug.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 13:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/passing-string-argument-in-a-datastep-from-one-macro-to-another/m-p/253792#M13400</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-02T13:10:45Z</dc:date>
    </item>
  </channel>
</rss>

