<?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: Updating global macro variable based on a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371884#M88844</link>
    <description>The quotes around Y are a mistake. I wasn't aware (but now am!) that I can't use %let in the data step. So how would I use call symput to do what I intended? Thanks!</description>
    <pubDate>Thu, 29 Jun 2017 19:47:46 GMT</pubDate>
    <dc:creator>DocMartin</dc:creator>
    <dc:date>2017-06-29T19:47:46Z</dc:date>
    <item>
      <title>Updating global macro variable based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371859#M88834</link>
      <description>I have a global variable called "switch", which by default is set to 'N'; If a certain condition occurs then I'd like switch be = 'Y'. The code I'm using always changes switch to 'Y', regardless of the condition. That's not right. Here's my code: data _NULL_; %let switch = N; if rand('UNIFORM') &amp;gt; 0.3 then do; %let switch = 'Y'; end; %put &amp;amp;switch; run; Any ideas? Thanks!</description>
      <pubDate>Thu, 29 Jun 2017 18:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371859#M88834</guid>
      <dc:creator>DocMartin</dc:creator>
      <dc:date>2017-06-29T18:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Updating global macro variable based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371869#M88835</link>
      <description>&lt;P&gt;Two problems: 1 you change it from N to 'Y' (why do you add quotes for Y?)&lt;/P&gt;
&lt;P&gt;2 You use %let let in a datastep, when you should use call symput&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What condition do you really want to use? Surely, not just randomly like shown in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 19:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371869#M88835</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-29T19:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Updating global macro variable based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371883#M88843</link>
      <description>&lt;P&gt;%LET statements are never part of a DATA step.&amp;nbsp; You might as well have coded:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let switch = N;&lt;/P&gt;
&lt;P&gt;%let switch = 'Y';&lt;/P&gt;
&lt;P&gt;%put &amp;amp;switch;&lt;/P&gt;
&lt;P&gt;data _NULL_;&lt;/P&gt;
&lt;P&gt;if rand('UNIFORM') &amp;gt; 0.3 then do;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That reflects what your program is actually doing.&amp;nbsp; However, the good news is that there are interfaces between a DATA step and macro language.&amp;nbsp; You could instead code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let switch = N;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;if rand('UNIFORM') &amp;gt; 0.3 then call symput('switch', 'Y');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;switch;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 19:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371883#M88843</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-29T19:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Updating global macro variable based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371884#M88844</link>
      <description>The quotes around Y are a mistake. I wasn't aware (but now am!) that I can't use %let in the data step. So how would I use call symput to do what I intended? Thanks!</description>
      <pubDate>Thu, 29 Jun 2017 19:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371884#M88844</guid>
      <dc:creator>DocMartin</dc:creator>
      <dc:date>2017-06-29T19:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Updating global macro variable based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371886#M88846</link>
      <description>That works! Thanks.</description>
      <pubDate>Thu, 29 Jun 2017 19:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-global-macro-variable-based-on-a-condition/m-p/371886#M88846</guid>
      <dc:creator>DocMartin</dc:creator>
      <dc:date>2017-06-29T19:52:44Z</dc:date>
    </item>
  </channel>
</rss>

