<?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: Best way to convert verbal response choices to numeric values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329330#M73663</link>
    <description>&lt;P&gt;Please post test data in the form of a datastep in future. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code is not tested as not typing that in:&lt;/P&gt;
&lt;PRE&gt;data want (drop=q:);
  set have;
  array q{38};
  array nq{38} 8;
  do i=1 to 38;
    select(q{i});
      when ("Not at all") nq{i}=0;
      when ("A little bit") nq{i}=1;
      ...;
      otherwise;
    end;
  end;
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Feb 2017 09:32:30 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-02-02T09:32:30Z</dc:date>
    <item>
      <title>Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329246#M73624</link>
      <description>&lt;P&gt;I have little experience with handling survey data with this many questions and that requires manipulation. &amp;nbsp;I have survey data with 38 questions and the responses are recorded in the dataset as&amp;nbsp;Not at all, A little bit, Somewhat, Quite a bit, &amp;nbsp;and Very much. &amp;nbsp;I am trying to convert the responses to numeric scores so they can be summed up. &amp;nbsp;I would like the recode to be Not at all=0, A little bit=1, Somewhat=2, Quite a bit=3 and Very much=4. My Q1-38 are a numbered range so I would think I should be able to use the range during recoding.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to avoid typing Q1-Q38 individually in an if then else statement. &amp;nbsp;I saw the "of" statement and thought it may be useful but it seems that the scenarios I have seen it used in are for mathematical operations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current format of the data:&lt;/P&gt;&lt;P&gt;patient ID VISIT Q1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Q2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q5.... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q38&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; somewhat &amp;nbsp; &amp;nbsp; very much &amp;nbsp; a little bit &amp;nbsp; somewhat &amp;nbsp; quite a bit.... &amp;nbsp; very much&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; a little bit&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;somewhat&amp;nbsp; &amp;nbsp;very much&amp;nbsp; &amp;nbsp;somewhat &amp;nbsp; quite a bit.... &amp;nbsp;&amp;nbsp;a little bit&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;450&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like it to be:&lt;/P&gt;&lt;P&gt;patient ID VISIT Q1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Q2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q5.... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Q38&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3.... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;450&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any suggestions on how I can handle this recoding? I am using SAS 9.4. &amp;nbsp;Please let me know if any additional information is needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 23:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329246#M73624</guid>
      <dc:creator>PaulaC</dc:creator>
      <dc:date>2017-02-01T23:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329250#M73628</link>
      <description>&lt;P&gt;You're trying to recode a variable and you can use either a format or IF/THEN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either way you should use an array to loop through all the variables. Create two arrays, one for the old values and one for the new values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some examples on how that might look:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/seminars/SAS_arrays/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 23:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329250#M73628</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-01T23:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329330#M73663</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep in future. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code is not tested as not typing that in:&lt;/P&gt;
&lt;PRE&gt;data want (drop=q:);
  set have;
  array q{38};
  array nq{38} 8;
  do i=1 to 38;
    select(q{i});
      when ("Not at all") nq{i}=0;
      when ("A little bit") nq{i}=1;
      ...;
      otherwise;
    end;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 09:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329330#M73663</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-02T09:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329441#M73706</link>
      <description>thank you</description>
      <pubDate>Thu, 02 Feb 2017 14:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329441#M73706</guid>
      <dc:creator>PaulaC</dc:creator>
      <dc:date>2017-02-02T14:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329444#M73708</link>
      <description>My apologies for not posting test data as a datastep. Thank you for the code. I will try it out.</description>
      <pubDate>Thu, 02 Feb 2017 14:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329444#M73708</guid>
      <dc:creator>PaulaC</dc:creator>
      <dc:date>2017-02-02T14:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329456#M73711</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could be done with a custom informat and arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;proc format;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;invalue code (upcase)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'NOT AT ALL'=0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;'LITTLE BIT'=1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;'SOMEWHAT'=2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;'QUITE A BIT'=3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;'VERY MUCH'=4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt; &lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;other=-1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data want;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set have;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;array Q {38} Q1-Q38;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;array R {38} R1-R38;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;do i = 1 to dim(Q);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; R(i)=input(Q(i),code.);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hope it helps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 15:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329456#M73711</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-02T15:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329462#M73714</link>
      <description>Thank you. Would you be able to clarify what dim does?</description>
      <pubDate>Thu, 02 Feb 2017 15:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329462#M73714</guid>
      <dc:creator>PaulaC</dc:creator>
      <dc:date>2017-02-02T15:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329490#M73721</link>
      <description>&lt;P&gt;Of course.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format is used to create a custom format to decode/transform specfic text into specific numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more info and examples, check the following paper of Lois Levin:&amp;nbsp;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, to handle all those variable I've used two associative arrays (one for input, the other for output, since they are of different data types).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Q holds the input values, R holds the results which is Q transformed with the custom format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i is just an auxilary variable to cycle from 1 to the total dimension of Q (= dim(Q) )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another paper with some great info about arrays:&amp;nbsp;&lt;A href="http://www2.sas.com/proceedings/sugi30/242-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/242-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 16:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329490#M73721</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-02T16:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to convert verbal response choices to numeric values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329495#M73724</link>
      <description>&lt;P&gt;Don't forget the corresponding DISPLAY format to show the text from the codes as needed. The reports at the end will likely want this somewhere.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 16:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-convert-verbal-response-choices-to-numeric-values/m-p/329495#M73724</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-02T16:23:24Z</dc:date>
    </item>
  </channel>
</rss>

