<?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: Creating a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628369#M185667</link>
    <description>&lt;P&gt;Here are some video tutorials on the subject.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://video.sas.com/detail/videos/sas-analytics-u/video/4573016759001/performing-conditional-logic-in-sas?autoStart=true&amp;amp;page=1" target="_blank"&gt;https://video.sas.com/detail/videos/sas-analytics-u/video/4573016759001/performing-conditional-logic-in-sas?autoStart=true&amp;amp;page=1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll need to go a step further because it appears you have multiple responses in the same field, such as "unsure, completetely agree". I usually recommend you go back to your survey software and change the export so each is in their own field.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you can use COUNTW() to count the number of words, and SCAN() to extract each word and apply the logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298381"&gt;@mt88&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a variable whose values are populated with likert scale responses (completely agree, agree, unsure, disagree, completely disagree). In some instances there are erroneous responses like "completely agree, agree" and "unsure, completely disagree". So the data might looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;completely agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;completely disagree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;unsure&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;disagree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;unsure, completely agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;unsure, disagree&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to create a new variable where completely agree = 1, agree = 2, unsure = 3, disagree = 4, completely disagree = 5, and everything else equals "."&amp;nbsp; ----So the resulting data variable would have these values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me with the code here? I am thinking if, then, else, but I am not sure how to write it. Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2020 22:46:41 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-02-28T22:46:41Z</dc:date>
    <item>
      <title>Creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628357#M185659</link>
      <description>&lt;P&gt;I have a variable whose values are populated with likert scale responses (completely agree, agree, unsure, disagree, completely disagree). In some instances there are erroneous responses like "completely agree, agree" and "unsure, completely disagree". So the data might looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;completely agree&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;agree&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;completely disagree&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;agree&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unsure&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;disagree&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unsure, completely agree&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unsure, disagree&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to create a new variable where completely agree = 1, agree = 2, unsure = 3, disagree = 4, completely disagree = 5, and everything else equals "."&amp;nbsp; ----So the resulting data variable would have these values:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me with the code here? I am thinking if, then, else, but I am not sure how to write it. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 21:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628357#M185659</guid>
      <dc:creator>mt88</dc:creator>
      <dc:date>2020-02-28T21:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628369#M185667</link>
      <description>&lt;P&gt;Here are some video tutorials on the subject.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://video.sas.com/detail/videos/sas-analytics-u/video/4573016759001/performing-conditional-logic-in-sas?autoStart=true&amp;amp;page=1" target="_blank"&gt;https://video.sas.com/detail/videos/sas-analytics-u/video/4573016759001/performing-conditional-logic-in-sas?autoStart=true&amp;amp;page=1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll need to go a step further because it appears you have multiple responses in the same field, such as "unsure, completetely agree". I usually recommend you go back to your survey software and change the export so each is in their own field.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you can use COUNTW() to count the number of words, and SCAN() to extract each word and apply the logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298381"&gt;@mt88&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a variable whose values are populated with likert scale responses (completely agree, agree, unsure, disagree, completely disagree). In some instances there are erroneous responses like "completely agree, agree" and "unsure, completely disagree". So the data might looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;completely agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;completely disagree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;unsure&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;disagree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;unsure, completely agree&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;unsure, disagree&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to create a new variable where completely agree = 1, agree = 2, unsure = 3, disagree = 4, completely disagree = 5, and everything else equals "."&amp;nbsp; ----So the resulting data variable would have these values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me with the code here? I am thinking if, then, else, but I am not sure how to write it. Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 22:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628369#M185667</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-28T22:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628389#M185673</link>
      <description>&lt;P&gt;That is fairly simple. I would use an infomat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue likert (upcase)
    'COMPLETELY AGREE' = 1
    'AGREE' = 2
    'UNSURE' = 3
    'DISAGREE' = 4  
    'COMPLETELY DISAGREE' = 5
    other= .
    ;
run; 

Data&amp;nbsp;want;
&amp;nbsp;&amp;nbsp;set&amp;nbsp;have;
&amp;nbsp;&amp;nbsp;value=input(response,likert.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I used the UPCASE option on the informat, as I assume the case of the text variables is not relevant (when values are read, all text is automatically converted to upper case before being evaluated).&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 06:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628389#M185673</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-02-29T06:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628778#M185861</link>
      <description>&lt;P&gt;Thanks very much. This did exactly what I needed.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 14:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628778#M185861</guid>
      <dc:creator>mt88</dc:creator>
      <dc:date>2020-03-02T14:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628825#M185875</link>
      <description>Check the last two records of your input data, if it matches your example data posted. This would not handle those cases.</description>
      <pubDate>Mon, 02 Mar 2020 16:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628825#M185875</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-02T16:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628830#M185876</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need anything that isn't "Completely Agree", "Agree", "Unsure", "Disagree", or "Completely Disagree" to be coded as missing, which it looks like this code does.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 16:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable/m-p/628830#M185876</guid>
      <dc:creator>mt88</dc:creator>
      <dc:date>2020-03-02T16:49:38Z</dc:date>
    </item>
  </channel>
</rss>

