<?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 How to pass SAS observation value in macro one by one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371683#M88800</link>
    <description>&lt;P&gt;I have a sas dataset(file_list) wherin I have kept the filenames of all files in a directory. I have a Macro that needs to pick all the filenames from&amp;nbsp;&lt;SPAN&gt;file_list and perform some operation one after the other. Can you help me to read the file names as a parameter to macro in a loop or something?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;work.file_list contains below records&amp;nbsp;say&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data file_list;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;macro transfer_file(file_path=);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend&amp;nbsp;&lt;SPAN&gt;transfer_&lt;/SPAN&gt;&lt;SPAN&gt;file;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;transfer_file(file_path=/user/MyFolder/file1);&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jun 2017 13:42:03 GMT</pubDate>
    <dc:creator>ReemaRoy</dc:creator>
    <dc:date>2017-06-29T13:42:03Z</dc:date>
    <item>
      <title>How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371683#M88800</link>
      <description>&lt;P&gt;I have a sas dataset(file_list) wherin I have kept the filenames of all files in a directory. I have a Macro that needs to pick all the filenames from&amp;nbsp;&lt;SPAN&gt;file_list and perform some operation one after the other. Can you help me to read the file names as a parameter to macro in a loop or something?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;work.file_list contains below records&amp;nbsp;say&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;file3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data file_list;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;macro transfer_file(file_path=);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend&amp;nbsp;&lt;SPAN&gt;transfer_&lt;/SPAN&gt;&lt;SPAN&gt;file;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;transfer_file(file_path=/user/MyFolder/file1);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 13:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371683#M88800</guid>
      <dc:creator>ReemaRoy</dc:creator>
      <dc:date>2017-06-29T13:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371684#M88801</link>
      <description>&lt;P&gt;A datastep is a loop, so you can use this to your advantage:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set work.file_list;
  call execute(cats('%transfer_file(file_path=',thevar,');'));
run;&lt;/PRE&gt;
&lt;P&gt;This assumes the file path is in a variable called thevar in file_list, replace that with your actual variable. &amp;nbsp;This will generate out a code line for each observation with the macro call which executes after the datastep has finished running.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 13:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371684#M88801</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-29T13:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371698#M88805</link>
      <description>&lt;P&gt;Thanks RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the ,thevar, representing the column name?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 14:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371698#M88805</guid>
      <dc:creator>ReemaRoy</dc:creator>
      <dc:date>2017-06-29T14:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371728#M88806</link>
      <description>&lt;P&gt;Yes, just replace thevar with whatever your column name is.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 14:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371728#M88806</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-29T14:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371749#M88814</link>
      <description>Look at the documentation for Call Execute, it has a fully worked example that helps to explain how to use it.</description>
      <pubDate>Thu, 29 Jun 2017 14:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/371749#M88814</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-29T14:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/372515#M89074</link>
      <description>&lt;P&gt;&lt;STRONG&gt;I am getting an error saying ERROR: Macro parameter contains syntax error.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; set work.file_list;&lt;BR /&gt;&amp;nbsp; call execute(cats('%transfer_file(',file_path=fname,'));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;While I run the same thing with the actual value It runs successfully&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; set work.file_list;&lt;BR /&gt;&amp;nbsp; call execute(cats('%transfer_file(',file_path=file1.xml,'));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything missing I need to specify with 'fname' ?&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jul 2017 08:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/372515#M89074</guid>
      <dc:creator>ReemaRoy</dc:creator>
      <dc:date>2017-07-02T08:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/372553#M89094</link>
      <description>&lt;P&gt;Here's a trick I use when using call execute.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Don't use a _Null_ dataset, give it a name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Create a string variable that has the macro call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Open dataset and check if String variable is being created correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Pass string variable to CALL EXECUTE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your call execute cats is incorrect. Untested but you should be able to debug it from here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data run_macros_list;
  set work.file_list;
string = cats('%transfer_file(file_path="', fname,'");");
  *call execute(string);
run;

Proc print;
Var string;
Run:&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Sun, 02 Jul 2017 14:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/372553#M89094</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-02T14:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/372666#M89136</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;has stated you can save what is generated to a dataset, you an also get this information from the log as code generated is included, much like if you included another file, so it will appear with + before each code line. &amp;nbsp;Now just looking at your code I can tell the quotes are not in the right place:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; call execute(cats('%transfer_file(',file_path=fname,'));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&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; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ^&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Between the two arrows here is where you problem lies. &amp;nbsp;To fix this move the quote:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; call execute(cats('%transfer_file(,file_path=',fname,');'));&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note how we are now concatenating the string:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%transfer_file(,file_path=&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;With the data from variable fname and then the string:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thus if abc.txt is the filename&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;'%transfer_file(,file_path=' + 'abc.txt' + ');'&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2017 07:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/372666#M89136</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-03T07:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass SAS observation value in macro one by one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/373310#M89301</link>
      <description>&lt;P&gt;Thanks RW9 and Reeza for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added &amp;nbsp; call symput('file_name', fname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And it retrieved the filename correctly from dataset. I have used your datastep and followed the procedure written to debug. It has helped me to achieve my Goals. Thanks&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Reema&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 14:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-SAS-observation-value-in-macro-one-by-one/m-p/373310#M89301</guid>
      <dc:creator>ReemaRoy</dc:creator>
      <dc:date>2017-07-05T14:34:58Z</dc:date>
    </item>
  </channel>
</rss>

