<?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 Consolidating responses to create a new variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12506#M1683</link>
    <description>Hi Colleagues,&lt;BR /&gt;
&lt;BR /&gt;
Would appreciate if any one of you could help me.&lt;BR /&gt;
&lt;BR /&gt;
I have a data set like this.&lt;BR /&gt;
&lt;BR /&gt;
Data hs;&lt;BR /&gt;
Input ID food_run;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
1 1&lt;BR /&gt;
2 2&lt;BR /&gt;
3 3&lt;BR /&gt;
4 3&lt;BR /&gt;
5 2&lt;BR /&gt;
6 1&lt;BR /&gt;
7 7 &lt;BR /&gt;
8 8&lt;BR /&gt;
9 9&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
In food-run variable, &lt;BR /&gt;
1=often true&lt;BR /&gt;
2=sometimes true&lt;BR /&gt;
3=never true&lt;BR /&gt;
4=don’t know&lt;BR /&gt;
5=refusal&lt;BR /&gt;
6=not stated&lt;BR /&gt;
&lt;BR /&gt;
I need to create a new variable called WORRIED like this.&lt;BR /&gt;
&lt;BR /&gt;
If the response for variable food_run = 1 or 2 then WORRIED=1&lt;BR /&gt;
If the response for variable food_run = 3 then WORRIED=2&lt;BR /&gt;
If the response for variable food_run = 4 or 5 or 6 then WORRIED=missing or . &lt;BR /&gt;
&lt;BR /&gt;
I attempted like this but this does not work properly.&lt;BR /&gt;
Data hs1;&lt;BR /&gt;
Set hs;&lt;BR /&gt;
If food_run = 1 or 2 then WORRIED=1;&lt;BR /&gt;
If food_run = 2 then WORRIED=2;&lt;BR /&gt;
Else WORRIED=.;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
Could you please assist to write the correct program.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
    <pubDate>Thu, 29 Apr 2010 16:04:32 GMT</pubDate>
    <dc:creator>Mirisage</dc:creator>
    <dc:date>2010-04-29T16:04:32Z</dc:date>
    <item>
      <title>Consolidating responses to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12506#M1683</link>
      <description>Hi Colleagues,&lt;BR /&gt;
&lt;BR /&gt;
Would appreciate if any one of you could help me.&lt;BR /&gt;
&lt;BR /&gt;
I have a data set like this.&lt;BR /&gt;
&lt;BR /&gt;
Data hs;&lt;BR /&gt;
Input ID food_run;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
1 1&lt;BR /&gt;
2 2&lt;BR /&gt;
3 3&lt;BR /&gt;
4 3&lt;BR /&gt;
5 2&lt;BR /&gt;
6 1&lt;BR /&gt;
7 7 &lt;BR /&gt;
8 8&lt;BR /&gt;
9 9&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
In food-run variable, &lt;BR /&gt;
1=often true&lt;BR /&gt;
2=sometimes true&lt;BR /&gt;
3=never true&lt;BR /&gt;
4=don’t know&lt;BR /&gt;
5=refusal&lt;BR /&gt;
6=not stated&lt;BR /&gt;
&lt;BR /&gt;
I need to create a new variable called WORRIED like this.&lt;BR /&gt;
&lt;BR /&gt;
If the response for variable food_run = 1 or 2 then WORRIED=1&lt;BR /&gt;
If the response for variable food_run = 3 then WORRIED=2&lt;BR /&gt;
If the response for variable food_run = 4 or 5 or 6 then WORRIED=missing or . &lt;BR /&gt;
&lt;BR /&gt;
I attempted like this but this does not work properly.&lt;BR /&gt;
Data hs1;&lt;BR /&gt;
Set hs;&lt;BR /&gt;
If food_run = 1 or 2 then WORRIED=1;&lt;BR /&gt;
If food_run = 2 then WORRIED=2;&lt;BR /&gt;
Else WORRIED=.;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
Could you please assist to write the correct program.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
      <pubDate>Thu, 29 Apr 2010 16:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12506#M1683</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-29T16:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidating responses to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12507#M1684</link>
      <description>If food_run = 1 or 2   should be if food_run in(1,2);  or &lt;BR /&gt;
If food_run = 1 or food_run = 2;</description>
      <pubDate>Thu, 29 Apr 2010 16:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12507#M1684</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-04-29T16:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidating responses to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12508#M1685</link>
      <description>Hi Flip,&lt;BR /&gt;
&lt;BR /&gt;
Thank you very much. &lt;BR /&gt;
&lt;BR /&gt;
I tried your both suggestions but they didn't work. However, I removed the statement 'else .' and then both of your suggestions worked well. &lt;BR /&gt;
&lt;BR /&gt;
Hope it is not an accident and it should be the way, isn't it?&lt;BR /&gt;
 &lt;BR /&gt;
Data hs1;&lt;BR /&gt;
Set hs;&lt;BR /&gt;
If food_run =1 or food_run= 2 then WORRIED=1;&lt;BR /&gt;
If food_run = 3 then WORRIED=2;&lt;BR /&gt;
&lt;THERE should="" be="" no=""&gt; &lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data hs1;&lt;BR /&gt;
Set hs;&lt;BR /&gt;
If food_run in(1,2)then WORRIED=1;&lt;BR /&gt;
If food_run = 3 then WORRIED=2;&lt;BR /&gt;
&lt;THERE should="" be="" no=""&gt; &lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
thank you&lt;BR /&gt;
&lt;BR /&gt;
Mirisage&lt;/THERE&gt;&lt;/THERE&gt;</description>
      <pubDate>Thu, 29 Apr 2010 16:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12508#M1685</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-29T16:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidating responses to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12509#M1686</link>
      <description>use an else if for the second one.&lt;BR /&gt;
&lt;BR /&gt;
else If food_run = 2 then WORRIED=2;</description>
      <pubDate>Thu, 29 Apr 2010 17:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12509#M1686</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-04-29T17:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidating responses to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12510#M1687</link>
      <description>Hi Flip, this is great!&lt;BR /&gt;
&lt;BR /&gt;
Worked very well.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again!&lt;BR /&gt;
&lt;BR /&gt;
Mirisage Neil</description>
      <pubDate>Thu, 29 Apr 2010 17:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Consolidating-responses-to-create-a-new-variable/m-p/12510#M1687</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-29T17:30:02Z</dc:date>
    </item>
  </channel>
</rss>

