<?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: Automatic variable creation in Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142191#M261659</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Everyone for helping me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a nice weekend.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 14 Jun 2014 00:36:44 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2014-06-14T00:36:44Z</dc:date>
    <item>
      <title>Automatic variable creation in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142187#M261655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My data is as below.&lt;/P&gt;&lt;P&gt;I want to create 3 variable New1 New2 New3 to store the value of the following comparison:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If var1&amp;gt;max_1 then New1=1; else New1=0;&lt;/P&gt;&lt;P&gt;If var1&amp;gt;max_2 then New2=1; else New2=0;&lt;/P&gt;&lt;P&gt;If var1&amp;gt;max_3 then New3=1; else New3=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I try to do it with Array. My problem is that I don't know how to tell SAS to create the Array of New1 New2 New3 automatically within the last section of the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var1 max_1 max_2 max_3;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;3 2 2 3&lt;/P&gt;&lt;P&gt;4 2 8 9&lt;/P&gt;&lt;P&gt;0 5 5 63&lt;/P&gt;&lt;P&gt;8 9 1 2&lt;/P&gt;&lt;P&gt;6 11 4 6&lt;/P&gt;&lt;P&gt;100 20 5 9&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want; set have;&lt;BR /&gt;array max(3) max_3-max_3;&lt;/P&gt;&lt;P&gt;do i=1 to 3;&lt;BR /&gt;if var1&amp;gt;max&lt;I&gt; then &lt;SPAN style="color: #ff0000;"&gt;NEW_VARIABLE&lt;I&gt;=1&lt;/I&gt;&lt;/SPAN&gt;;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 20:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142187#M261655</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2014-06-13T20:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic variable creation in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142188#M261656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array max max_1-max_3;&lt;BR /&gt;array new new1-new3;&lt;BR /&gt;do i=1 to dim(max);&lt;BR /&gt;new(i)=ifn( var1&amp;gt;max(i),1,0);&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 20:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142188#M261656</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2014-06-13T20:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic variable creation in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142189#M261657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input var1 max_1 max_2 max_3;&lt;BR /&gt;datalines;&lt;BR /&gt;3 2 2 3&lt;BR /&gt;4 2 8 9&lt;BR /&gt;0 5 5 63&lt;BR /&gt;8 9 1 2&lt;BR /&gt;6 11 4 6&lt;BR /&gt;100 20 5 9&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(drop=i); &lt;BR /&gt;set have;&lt;BR /&gt;array &lt;STRONG&gt;current_max&lt;/STRONG&gt;(3) max_1-max_3; &lt;STRONG&gt;/* Avoid using max as this is sas function name */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;array NEW_VARIABLE(3) new1-new3; /* New array */&lt;/STRONG&gt;&lt;BR /&gt;do i=1 to 3;&lt;BR /&gt;if var1&amp;gt;current_max&lt;I&gt; then NEW_VARIABLE&lt;I&gt;=1;&lt;BR /&gt;else NEW_VARIABLE&lt;I&gt;=0;&lt;BR /&gt;end;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=want;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 21:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142189#M261657</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-06-13T21:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic variable creation in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142190#M261658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS creates variables when you reference them.&lt;/P&gt;&lt;P&gt;So you can use the ARRAY statement to "create" the variables. &lt;/P&gt;&lt;P&gt;&amp;nbsp; Or a LENGTH statement.&lt;/P&gt;&lt;P&gt;Or any number of other statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also note that SAS evaluates logical expressions to 1 (true) or 0 (false).&lt;/P&gt;&lt;P&gt;So here is simple program to do what you requested. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; max max_1-max_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; new new1-new3 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;over&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; max ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; new = (var1 &amp;gt; max) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 23:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142190#M261658</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-06-13T23:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic variable creation in Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142191#M261659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Everyone for helping me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a nice weekend.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 14 Jun 2014 00:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatic-variable-creation-in-Array/m-p/142191#M261659</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2014-06-14T00:36:44Z</dc:date>
    </item>
  </channel>
</rss>

