<?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: simple array question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443594#M110990</link>
    <description>&lt;P&gt;Thanks - little tips like that really help me out in understanding SAS language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if I wanted to keep only those records/observations (the whole row of data) with '9359' or '9351'? Would I use a keep statement?&lt;/P&gt;</description>
    <pubDate>Thu, 08 Mar 2018 02:49:33 GMT</pubDate>
    <dc:creator>Angmar</dc:creator>
    <dc:date>2018-03-08T02:49:33Z</dc:date>
    <item>
      <title>simple array question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443576#M110980</link>
      <description>&lt;P&gt;New SAS user - trying to make an array that creates a new variable with observations as '1' when it finds either 9359 or 9351 (character, not numeric) in the array variables.&lt;/P&gt;&lt;P&gt;Here's my code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data cuthip;&lt;BR /&gt;set allrecords;&lt;BR /&gt;array procedure (3) $ prcode1-prcode3;&lt;BR /&gt;do x=(1-3);&lt;BR /&gt;if procedure(x) = ('9351'OR '9359') then procedure (x)=1;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I keep getting the error statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;336:4 336:20 336:29&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;336:42&lt;BR /&gt;ERROR: Array subscript out of range at line 336 column 4.&lt;BR /&gt;ikn=1 prcode1=1257 prcode2=1165 prcode3=1165 rescode=angmar cats=amino x=-2 _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: There were 1 observations read from the data set WORK.ALLRECORDS.&lt;BR /&gt;WARNING: The data set WORK.CUTHIP may be incomplete. When this step was stopped there were 0 observations&lt;BR /&gt;and 7 variables.&lt;BR /&gt;WARNING: Data set WORK.CUTHIP was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 00:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443576#M110980</guid>
      <dc:creator>Angmar</dc:creator>
      <dc:date>2018-03-08T00:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: simple array question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443579#M110981</link>
      <description>&lt;P&gt;Try assigning a character constant to procedure[x] in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if procedure(x) = ('9351'OR '9359') then procedure (x)=1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;with '1'.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 01:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443579#M110981</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-03-08T01:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: simple array question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443582#M110984</link>
      <description>&lt;P&gt;As a new user, your errors are understandable.&amp;nbsp; Here are a few issues with your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do x=(1-3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1-3 is -2.&amp;nbsp; You could just as easily have coded:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do x=-2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get x to go from 1 to 3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do x=1 to 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, to compare to a list of values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if procedure(x) in ('9351' '9359') then ...............&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, you said you wanted to create a new variable.&amp;nbsp; But instead, your code re-assigns a value to an existing variable.&amp;nbsp; This would be an improvement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if procedure(x) in ('9351' '9359') then newvar=1;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 01:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443582#M110984</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-08T01:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: simple array question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443594#M110990</link>
      <description>&lt;P&gt;Thanks - little tips like that really help me out in understanding SAS language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if I wanted to keep only those records/observations (the whole row of data) with '9359' or '9351'? Would I use a keep statement?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 02:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443594#M110990</guid>
      <dc:creator>Angmar</dc:creator>
      <dc:date>2018-03-08T02:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: simple array question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443625#M111003</link>
      <description>&lt;P&gt;To keep or remove observations (based on a calculated variable) use an IF statement.&amp;nbsp; IF without THEN is totally different than IF-THEN.&amp;nbsp; To subset the observations, you could add this as the final statement in the DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if newvar=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Often an IF statement appears earlier in the DATA step.&amp;nbsp; It is usually most efficient to place it early.&amp;nbsp; But here you need to calculate NEWVAR first.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 05:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-array-question/m-p/443625#M111003</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-08T05:31:33Z</dc:date>
    </item>
  </channel>
</rss>

