<?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: data driven code with Macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460634#M284668</link>
    <description>Thanks mate, I am using SAS Studio where its Run; statement is not generally considered mandatory, but it solved the problem. Could you elaborate how it works because when "Country" is taken as variable instead of Gender in orion.customer, same code worked without any problem</description>
    <pubDate>Tue, 08 May 2018 06:54:34 GMT</pubDate>
    <dc:creator>Pradeeptdalal28</dc:creator>
    <dc:date>2018-05-08T06:54:34Z</dc:date>
    <item>
      <title>data driven code with Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460542#M284666</link>
      <description>&lt;P&gt;&lt;STRONG&gt;While using this code &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%macro SPLIT (DATA = , VAR &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; ;&lt;BR /&gt;PROC SORT DATA = &amp;amp;DATA (KEEP = &amp;amp;VAR) OUT = SORT_&amp;amp;VAR NODUPKEY;&lt;BR /&gt;BY &amp;amp;VAR;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;BR /&gt;SET SORT_&amp;amp;VAR end = final;&lt;BR /&gt;CALL SYMPUTX ("&amp;amp;VAR"!!left(_n_), &amp;amp;VAR);&lt;BR /&gt;if final then call symputx('Count',_n_);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;count;&lt;BR /&gt;data &amp;amp;&amp;amp;&amp;amp;VAR&amp;amp;i;&lt;BR /&gt;set &amp;amp;DATA;&lt;BR /&gt;where &amp;amp;VAR = "&amp;amp;&amp;amp;&amp;amp;VAR&amp;amp;i";&lt;BR /&gt;run;&lt;BR /&gt;proc print data = &amp;amp;&amp;amp;&amp;amp;VAR&amp;amp;I;&lt;BR /&gt;title "Customer Data for &amp;amp;VAR: &amp;amp;&amp;amp;&amp;amp;VAR&amp;amp;I ";&lt;BR /&gt;%end;&lt;BR /&gt;%mend SPLIT;&lt;/P&gt;&lt;P&gt;%SPLIT (DATA = ORION.EMPLOYEE_PAYROLL, VAR = EMPLOYEE_GENDER)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I am getting error that Employee_gender1 was not resolved, cant&amp;nbsp; understand why because&amp;nbsp;&amp;nbsp;EMPLOYEE_GENDER2 was resolved to Male; and its clearly visible in datafile sort_EMPLOYEE_GENDER that variable employee_gender has only two values - Female and Male.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 18:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460542#M284666</guid>
      <dc:creator>Pradeeptdalal28</dc:creator>
      <dc:date>2018-05-07T18:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: data driven code with Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460555#M284667</link>
      <description>&lt;P&gt;It's generally a good idea to add RUN statements ending your DATA and PROC steps.&amp;nbsp; In this case, it's an essential idea.&amp;nbsp; Add them, and the problem should vanish.&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 18:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460555#M284667</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-07T18:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: data driven code with Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460634#M284668</link>
      <description>Thanks mate, I am using SAS Studio where its Run; statement is not generally considered mandatory, but it solved the problem. Could you elaborate how it works because when "Country" is taken as variable instead of Gender in orion.customer, same code worked without any problem</description>
      <pubDate>Tue, 08 May 2018 06:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460634#M284668</guid>
      <dc:creator>Pradeeptdalal28</dc:creator>
      <dc:date>2018-05-08T06:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: data driven code with Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460693#M284669</link>
      <description>&lt;P&gt;There are too many unknowns to speculate about why the program would work in some cases.&amp;nbsp; For example, is there a global macro variable named COUNT?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the reason that RUN is necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA and PROC statements don't run until SAS "knows" that the step is complete.&amp;nbsp; Usually that means SAS encounters a subsequent DATA, PROC, or CARDS statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, the DATA _NULL_ step doesn't run soon enough.&amp;nbsp; It's conceivable that the %DO loop that follows would be adding more statements that should be part of the same DATA step.&amp;nbsp; So the DATA _NULL_ step doesn't actually run until SAS encounters&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA &amp;amp;&amp;amp;&amp;amp;VAR&amp;amp;I;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But resolving that second DATA statement requires that the DATA _NULL_ step already has executed, to create the macro variable that becomes the name of the next data set.&amp;nbsp; RUN cures the timing issue, forcing the DATA _NULL_ step to finish before executing the %DO loop.&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 13:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460693#M284669</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-08T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: data driven code with Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460729#M284670</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191027"&gt;@Pradeeptdalal28&lt;/a&gt; wrote:&lt;BR /&gt;Thanks mate, I am using SAS Studio where its Run; statement is not generally considered mandatory, but it solved the problem. Could you elaborate how it works because when "Country" is taken as variable instead of Gender in orion.customer, same code worked without any problem&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The same rules for data/proc step boundaries for execution exist in the other forms of SAS as well.&lt;/P&gt;
&lt;P&gt;However using them explicitly is still a good idea. As you have just discovered and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;provided just one of the potential issues when using macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't &lt;STRONG&gt;have &lt;/STRONG&gt;to name data sets in a data step either. SAS will happily create a new data set every time you run something like:&lt;/P&gt;
&lt;PRE&gt;data;
  set sashelp.class; 
run;&lt;/PRE&gt;
&lt;P&gt;of course keeping track of which dataN you actually want can become a chore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also do not &lt;STRONG&gt;have&lt;/STRONG&gt; to name the data set used by many procs for input:&lt;/P&gt;
&lt;PRE&gt;proc print;
run;&lt;/PRE&gt;
&lt;P&gt;will happily print the last created data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In macro's using either of these code short cuts is very likely to lead to unexpected results, especially if your procedure references a variable that isn't actually in the last created data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Have to" versus "good idea" decisions often result from experience (often defined as learning when something fouls up epically).&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 15:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-driven-code-with-Macros/m-p/460729#M284670</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-08T15:34:40Z</dc:date>
    </item>
  </channel>
</rss>

