<?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: array and do over question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301091#M270379</link>
    <description>&lt;P&gt;I made a mistake in my original post, I didn't mean to say "number CHARACTER", I want to change these text values into number values.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2016 17:54:13 GMT</pubDate>
    <dc:creator>jcqbano</dc:creator>
    <dc:date>2016-09-27T17:54:13Z</dc:date>
    <item>
      <title>array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301080#M270376</link>
      <description>&lt;P&gt;I have a 10 item questionnaire in which all 10 questions have the same answer choices: “never”, ‘almost never”, “sometime”, “fairly often” and “very often”. I want to change the values in the dataset from text characters to number characters ranging from 0 to 4. However, I do not want to write 500 if/then statements. I need a code that searches all 10 questions finds the specified “text” and changes it to the corresponding number value.&lt;/P&gt;
&lt;P&gt;I tried to do arrays and do over statements but I don’t know how to get the code just right. How can I modify the code below to produce what I want?&amp;nbsp; Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array b pss_oppera_q1-pss_oppera_q10;&lt;/P&gt;
&lt;P&gt;do over b;&lt;/P&gt;
&lt;P&gt;if b = "Never" then b = 0;&lt;/P&gt;
&lt;P&gt;if b = "Almost never" then b = 1;&lt;/P&gt;
&lt;P&gt;if b = "Sometimes" then b = 2;&lt;/P&gt;
&lt;P&gt;if b = "Fairly often" then b = 3;&lt;/P&gt;
&lt;P&gt;if b = "Very often" then b = 4;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 17:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301080#M270376</guid>
      <dc:creator>jcqbano</dc:creator>
      <dc:date>2016-09-27T17:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301084#M270377</link>
      <description>&lt;P&gt;Assuming that you are actually replacing the original variables, those variables are character. &amp;nbsp;So you need to put the values in quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do over b;&lt;/P&gt;
&lt;P&gt;if b = "Never" then b = "0";&lt;/P&gt;
&lt;P&gt;else if b = "Almost never" then b = "1";&lt;/P&gt;
&lt;P&gt;else if b = "Sometimes" then b = "2";&lt;/P&gt;
&lt;P&gt;else if b = "Fairly often" then b = "3";&lt;/P&gt;
&lt;P&gt;else if b = "Very often" then b = "4";&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 17:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301084#M270377</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-27T17:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301087#M270378</link>
      <description>&lt;P&gt;Or create a new variable rather than leave it as B.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that do over loops are deprecated but support remains for legacy.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 17:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301087#M270378</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-27T17:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301091#M270379</link>
      <description>&lt;P&gt;I made a mistake in my original post, I didn't mean to say "number CHARACTER", I want to change these text values into number values.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 17:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301091#M270379</guid>
      <dc:creator>jcqbano</dc:creator>
      <dc:date>2016-09-27T17:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301093#M270381</link>
      <description>&lt;P&gt;To save numeric values, you will need a new set of numeric variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array c num_q1 - num_q10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then inside the loop it will probably work to say:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do over b;&lt;/P&gt;
&lt;P&gt;if b = "Never" then c = 0;&lt;/P&gt;
&lt;P&gt;if b = "Almost never" then c = 1;&lt;/P&gt;
&lt;P&gt;if b = "Sometimes" then c = 2;&lt;/P&gt;
&lt;P&gt;if b = "Fairly often" then c = 3;&lt;/P&gt;
&lt;P&gt;if b = "Very often" then c = 4;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't test this right now, but it should work.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 17:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301093#M270381</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-27T17:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301110#M270382</link>
      <description>&lt;P&gt;Formats are another way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
invalue Response upcase
"NEVER"        = 0
"ALMOST NEVER" = 1
"SOMETIMES"    = 2
"FAIRLY OFTEN" = 3
"VERY OFTEN"   = 4
;
run;

/* in a data step*/
array b pss_oppera_q1-pss_oppera_q10;
array c num_q1 - num_q10;
do i=1 to dim(b);
   c[i]= input(b[i],Response.);
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your original data was read from a text file you could use the custom informat when reading that and start with the numeric values in the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I used the Upcase option in case your example data may vary from the actual values by case of the letters.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2016 19:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301110#M270382</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-27T19:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: array and do over question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301174#M270383</link>
      <description>&lt;P&gt;Not really on topic for the question, but you can replace the if syntax with a select for readability terms:&lt;/P&gt;
&lt;PRE&gt;array b...;
array c...;
do over b;
  select(b);
    when ("Never") c=0;
    when ("Almost never") c=1;
    when ("Sometimes") c=2;
    when ("Fairly Often") c=3;
    otherwise c=4;
  end;
end;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2016 08:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-and-do-over-question/m-p/301174#M270383</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-28T08:34:07Z</dc:date>
    </item>
  </channel>
</rss>

