<?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: Need explantion why these lines of code does not work. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144204#M28765</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for your explanation.&amp;nbsp; It was very informative and helpful.&amp;nbsp; If it is not too much, could you explain why the following does not work as well:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test&lt;/P&gt;&lt;P&gt;Data test (drop=drugs dm mod nwords);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drugs="&amp;amp;drug";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dm = ',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod = 'oq';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nwords = countw(drugs, dm, mod);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to nwords;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&amp;amp;i=strip(scan(drugs, &amp;amp;i, dm, mod));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this because, similar as your explanation for my previous question, there is a mismatch with data step code and macro code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Jan 2015 17:30:04 GMT</pubDate>
    <dc:creator>dtchoi86</dc:creator>
    <dc:date>2015-01-29T17:30:04Z</dc:date>
    <item>
      <title>Need explantion why these lines of code does not work.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144202#M28763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need help understanding why nwords will not resolve in the following lines of code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let drug=EXAMPLEONE, EXAMPLETWO;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;Data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drugs="&amp;amp;drug";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dm = ',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod = 'oq';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nwords = countw(drugs, dm, mod);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('nwords',nwords);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to &amp;amp;nwords;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&amp;amp;i=strip(scan(drugs, &amp;amp;i, dm, mod));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this works:&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;Data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drugs="&amp;amp;drug";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dm = ',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod = 'oq';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nwords = countw(drugs, dm, mod);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('nwords',nwords);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drugs="&amp;amp;drug";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dm = ',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod = 'oq';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nwords = countw(drugs, dm, mod);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to &amp;amp;nwords;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&amp;amp;i=strip(scan(drugs, &amp;amp;i, dm, mod));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Jan 2015 14:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144202#M28763</guid>
      <dc:creator>dtchoi86</dc:creator>
      <dc:date>2015-01-29T14:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need explantion why these lines of code does not work.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144203#M28764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are mixing up macro code and datastep code is the reason:&lt;/P&gt;&lt;P&gt;So, your macro test.&amp;nbsp; When it is called it will expand all the macro code into useable SAS code, then send that to the compiler.&amp;nbsp; So your call to symput doesn't get actioned until *after* all the macro has been evaluated, hence %do I=1 to &amp;amp;Nwords will result in a problem as nwords is not defined.&amp;nbsp; What are you attempting to do, as from the code above there is no reason to resort to macro code anyway.&lt;/P&gt;&lt;P&gt;Data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drugs="&amp;amp;drug";&amp;nbsp; /* Don't know where this comes from? */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dm = ',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod = 'oq';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array drug{100} $200.;&amp;nbsp; /* I am just assuming no more than 100 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to countw(drugs, dm, mod);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug{I}=strip(scan(drugs,i,dm,mod));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Jan 2015 14:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144203#M28764</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-29T14:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need explantion why these lines of code does not work.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144204#M28765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for your explanation.&amp;nbsp; It was very informative and helpful.&amp;nbsp; If it is not too much, could you explain why the following does not work as well:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test&lt;/P&gt;&lt;P&gt;Data test (drop=drugs dm mod nwords);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drugs="&amp;amp;drug";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dm = ',';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod = 'oq';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nwords = countw(drugs, dm, mod);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to nwords;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drug&amp;amp;i=strip(scan(drugs, &amp;amp;i, dm, mod));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this because, similar as your explanation for my previous question, there is a mismatch with data step code and macro code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Jan 2015 17:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144204#M28765</guid>
      <dc:creator>dtchoi86</dc:creator>
      <dc:date>2015-01-29T17:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need explantion why these lines of code does not work.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144205#M28766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thats correct.&amp;nbsp; In step one your macro parts are expanded/resolved, as at that point nwords has not been created it fails.&amp;nbsp; So think of it this way, when the macro-preprocessor works it is trying to create a full base SAS program with nothing macro left in.&amp;nbsp; That code is then passed onto the compiler to be actioned.&amp;nbsp; So nwords is part of the datastep in the second step, but you are trying to reference it in macro language in step 1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Jan 2015 18:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-explantion-why-these-lines-of-code-does-not-work/m-p/144205#M28766</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-29T18:51:11Z</dc:date>
    </item>
  </channel>
</rss>

