<?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: Macro Numeric Var Creation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198659#M37232</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;status&amp;amp;i will resolve to "status1", "status2", and so on. Note that I used the quotes to make clear that we are dealing with strings here.&lt;/P&gt;&lt;P&gt;When the macro compares "status1" to "1" (because macro values are ALWAYS character), this condition will &lt;SPAN style="text-decoration: underline;"&gt;never&lt;/SPAN&gt; be true. The same goes for "dpd1" and so on.&lt;/P&gt;&lt;P&gt;Since there never has been a declaration of macro variable gb1_, all the references to it will fail.&lt;/P&gt;&lt;P&gt;If macro variable gb1_ was set to X, then &amp;amp;gb1_&amp;amp;i would resolve to X1 in the first iteration of the macro do loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, what do you want to achieve (logically)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jun 2015 11:14:05 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2015-06-03T11:14:05Z</dc:date>
    <item>
      <title>Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198656#M37229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to create multiple flags in my dataset GB1_1, GB1_2, ....... GB1_36, but failing miserably, how do I create numeric variables using macro code (below is what I tried)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro gb1(howmany);&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;howmany;&lt;/P&gt;&lt;P&gt;%if status&amp;amp;i = 1 %then %let &amp;amp;gb1_&amp;amp;i = %syseval(1*1);&lt;BR /&gt;%else %if status&amp;amp;i = 2 %then %let &amp;amp;gb1_&amp;amp;i = %syseval(1*1);&lt;BR /&gt;%else %if dpd&amp;amp;i &amp;gt;= 2 %then %let &amp;amp;gb1_&amp;amp;i = %syseval(1*1);&lt;BR /&gt;%else %if ((dpd&amp;amp;i &amp;lt; 2) and (dpd&amp;amp;i &amp;gt;= 1)) %then %let &amp;amp;gb1_&amp;amp;i = %syseval(2*1);&lt;BR /&gt;%else %let &amp;amp;gb1_&amp;amp;i = %syseval(0*1);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend gb1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;GB takes the value 0,1,2 dependent on the conditions above&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 06:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198656#M37229</guid>
      <dc:creator>mwf763</dc:creator>
      <dc:date>2015-06-03T06:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198657#M37230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is status&lt;EM&gt;n&lt;/EM&gt; a variable in your data step?&lt;/P&gt;&lt;P&gt;Macro logic can handle creation of regular programming syntax, but not based on values/conditions within a data step.&lt;/P&gt;&lt;P&gt;If you need to create and assign dynamic no variable depending on values in a data step, it's quite complex - not quite understand the logic in your attempt.&lt;/P&gt;&lt;P&gt;What do your try to achieve - what does the logic represent?&lt;/P&gt;&lt;P&gt;being a data modeler, creating lot's of variables/columns is seldom a good way forward. Preparing for data mining is one of very few use cases I know of.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198657#M37230</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-06-03T10:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198658#M37231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Provide example (test data in a datastep), required output.&amp;nbsp; I can't see what your trying to do here.&amp;nbsp; Macro variables are *always* character.&amp;nbsp; Macro language is basically a code generator, nothing more.&amp;nbsp; Logic should be done in Base SAS.&amp;nbsp; If you really need a macro flag then:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if &amp;amp;STATUS1="Y" then result="Y";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else result="N";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('RESULT',result);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198658#M37231</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-03T10:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198659#M37232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;status&amp;amp;i will resolve to "status1", "status2", and so on. Note that I used the quotes to make clear that we are dealing with strings here.&lt;/P&gt;&lt;P&gt;When the macro compares "status1" to "1" (because macro values are ALWAYS character), this condition will &lt;SPAN style="text-decoration: underline;"&gt;never&lt;/SPAN&gt; be true. The same goes for "dpd1" and so on.&lt;/P&gt;&lt;P&gt;Since there never has been a declaration of macro variable gb1_, all the references to it will fail.&lt;/P&gt;&lt;P&gt;If macro variable gb1_ was set to X, then &amp;amp;gb1_&amp;amp;i would resolve to X1 in the first iteration of the macro do loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, what do you want to achieve (logically)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 11:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198659#M37232</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-06-03T11:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198660#M37233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just a single line from your code illustrates the issues you have to fix:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if status&amp;amp;i = 1 %then %let &amp;amp;gb1_&amp;amp;i = %syseval(1*1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, it needs to be simplified.&amp;nbsp; Assigning a numeric value is straightforward and does not require a function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if status&amp;amp;i = 1 %then %let &amp;amp;gb1_&amp;amp;i = 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you were to use a function, there is no function named %SYSEVAL.&amp;nbsp; There's %EVAL, and %SYSEVALF, but not %SYSEVAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, what is the outcome supposed to be?&amp;nbsp; Assigning a value to the macro variable GB1_1 should remove an ampersand:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if status&amp;amp;i = 1 %then %let gb1_&amp;amp;i = 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the intended result is something different, you will need to explain.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, what in the world is STATUS1 supposed to be?&amp;nbsp; A macro variable named STATUS1?&amp;nbsp; A DATA step variable named STATUS1?&amp;nbsp; A series of 7 characters "STATUS1"?&amp;nbsp; You will definitely need to explain that as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 14:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198660#M37233</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-03T14:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198661#M37234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like you want to use ARRAY instead of macro logic.&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array s&amp;nbsp; status1-status36 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array d dpd1-dpd36 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array g gb1-gb36 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(s);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if s(i) =1 then g(i)=1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 15:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198661#M37234</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-06-03T15:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Numeric Var Creation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198662#M37235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll back up Tom's answer: use arrays&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and suggest assignment with a select series block&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = dim(s);&lt;/P&gt;&lt;P&gt;select;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; when() g(i) =1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; when() g(i) =2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; otherwise g(i) =0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 21:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Numeric-Var-Creation/m-p/198662#M37235</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-03T21:48:23Z</dc:date>
    </item>
  </channel>
</rss>

