<?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: How do I feed data step loop iterator value to macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396332#M278138</link>
    <description>&lt;P&gt;There's no source of data for this DATA step. &amp;nbsp;Are you expecting that PATH_1 and PATH_2 are actually macro variables? &amp;nbsp;If so, you could simply code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data dataset;&lt;/P&gt;
&lt;P&gt;length path $ 200;&lt;/P&gt;
&lt;P&gt;pathvar = "&amp;amp;path_1";&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;pathvar&amp;nbsp;= "&amp;amp;path_2";&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Sep 2017 13:51:12 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-09-15T13:51:12Z</dc:date>
    <item>
      <title>How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396308#M278134</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am somewhat&amp;nbsp;new to SAS programming and pretty confused about SAS macros. I hope you can help me out. I am trying to create a dataset containing locations for different files. In order to do that I have a dataset loop which executes a macro that assigns the path.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro chosepath(i);&lt;BR /&gt; %global path;&lt;BR /&gt; %if &amp;amp;i = 1 %then %let path = path_1;&lt;BR /&gt; %if &amp;amp;i = 2 %then %let path = path_2;&lt;BR /&gt; %else %let path = nopath;&lt;BR /&gt;%mend chosepath;&lt;BR /&gt;&lt;BR /&gt;data dataset;&lt;BR /&gt; do i = 1 to 2;&lt;BR /&gt; %chosepath(i);&lt;BR /&gt; pathvar = "&amp;amp;path";&lt;BR /&gt; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;The problems is that the %if statements are never true. In stead of feeding the iterator (1, 2 ..) to the macro it&amp;nbsp;always&amp;nbsp;gets the iterator name (i). Is there any way&amp;nbsp;for the macro to get the actual value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396308#M278134</guid>
      <dc:creator>brink</dc:creator>
      <dc:date>2017-09-15T13:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396309#M278135</link>
      <description>&lt;P&gt;Yes, classic misunderstanding of what Macro is and how it relates to Base SAS.&lt;/P&gt;
&lt;P&gt;Base SAS is the programming language. &amp;nbsp;Macro SAS is a text generator which then feeds into Base SAS. &amp;nbsp;So you %if statement resolves&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;/U&gt; the datastep ever starts execution. &amp;nbsp;You have to think of it this way:&lt;/P&gt;
&lt;P&gt;Text -&amp;gt; Macro Preprocessort -&amp;gt; full Code file -&amp;gt; SAS Compliler&lt;/P&gt;
&lt;P&gt;In that order sequentially, so all macro is resolved before getting anywhere near compilation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would ask why you want to do this at all as the code makes no sense, as with 99.9% of all macro code I have seen it is just adding a layer of obfuscation for no benefit, just do:&lt;/P&gt;
&lt;PRE&gt;data dataset;
  do i=1 to 2;
    pathvar=cats("path_",put(i,1.));
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note that calling your dataset "dataset is not recommended.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396309#M278135</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-15T13:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396315#M278136</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The paths are unfortunately not sqeuential but could be path_1 = C:\somefolder\anotherfolder, path_2 = F:\entirelydifferentfolder ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I cange the line to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%chosepath(2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then the %if statement resolves correctly (but of course only gives me path 2).&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396315#M278136</guid>
      <dc:creator>brink</dc:creator>
      <dc:date>2017-09-15T13:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396331#M278137</link>
      <description>&lt;P&gt;Please supply something which illustrates your problem then, I can only work with what you provide. &amp;nbsp;Irrespective of what the logic is, macro is not the way forward. &amp;nbsp;If you have a few paths then put them in a dataset, it then becomes a simple matter to merge them on:&lt;/P&gt;
&lt;PRE&gt;data paths;
  no=1;  path="c:\something"; output;
  no=2; path="f:\somethingelse"; output;
run;

data want;
  merge have paths;
  by no;
run;
&lt;/PRE&gt;
&lt;P&gt;Path will then be merged on where they no matches.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396331#M278137</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-15T13:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396332#M278138</link>
      <description>&lt;P&gt;There's no source of data for this DATA step. &amp;nbsp;Are you expecting that PATH_1 and PATH_2 are actually macro variables? &amp;nbsp;If so, you could simply code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data dataset;&lt;/P&gt;
&lt;P&gt;length path $ 200;&lt;/P&gt;
&lt;P&gt;pathvar = "&amp;amp;path_1";&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;pathvar&amp;nbsp;= "&amp;amp;path_2";&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396332#M278138</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-15T13:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396335#M278139</link>
      <description>&lt;P&gt;If you want to feed a list of data into your data step, you can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let pathvar=path_1,path_2;

data dataset;
do i = 1 to 2;
  pathvar = scan("&amp;amp;pathvar",i,',');
  output;
end;
run;

proc print data=dataset noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;i    pathvar

1    path_1 
2    path_2 
&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396335#M278139</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-15T13:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396600#M278140</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/145494"&gt;@brink&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;May be explain us the bigger problem you want to solve, i.e. is this about reading same structured text files from multiple locations into a common SAS dataset?&lt;/P&gt;
&lt;P&gt;It also really helps if you can provide sample data or at least explain as detailed as possible what you have, what problem you want to solve and what detail you need help with.&lt;/P&gt;
&lt;P&gt;It also helps if you can provide the code you've already implemented (whether working or not - you've done this already) as this often also helps us to understand where you're coming from and it also shows us your level of SAS expertise so we can give you answers on the right level.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Sep 2017 23:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396600#M278140</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-16T23:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I feed data step loop iterator value to macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396745#M278141</link>
      <description>&lt;P&gt;Perfect. This is exactly what I needed. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted my variables to stay as macro variables for as longs as possible to avoid truncation problems when&amp;nbsp;concatenatiing various parts of a path, file name, version and file type. The total path should only be saved in the dataset when the combinations are done.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 08:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-feed-data-step-loop-iterator-value-to-macro/m-p/396745#M278141</guid>
      <dc:creator>brink</dc:creator>
      <dc:date>2017-09-18T08:27:38Z</dc:date>
    </item>
  </channel>
</rss>

