<?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 creating a new variable with some conditions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75970#M22051</link>
    <description>Hi colleagues,&lt;BR /&gt;
I have a data set (10,000 obs) like this .&lt;BR /&gt;
&lt;BR /&gt;
Data MDI;&lt;BR /&gt;
Input ID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10; /*ID=Household ID*/&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1 2 2 1 2 1 2 1 1 1 &lt;BR /&gt;
2 2 2 2 1 1 1 1 1 1 1&lt;BR /&gt;
3 1 1 1 1 1 1 1 1 2 1&lt;BR /&gt;
;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
I need to create a new variable called deprived where deprived=1 if you get two or more 2 s for variables Q1 to Q10, else deprived =2&lt;BR /&gt;
&lt;BR /&gt;
For instance, the new variable deprived for these three households should get following values:&lt;BR /&gt;
&lt;BR /&gt;
For first household, deprived =1 (because there are four 2 s)&lt;BR /&gt;
For second household, deprived =1 (because there are three 2 s)&lt;BR /&gt;
For third household, deprived =2 (because there is only one 2 )&lt;BR /&gt;
&lt;BR /&gt;
Could you please help me know with the codes to create the new variable called deprived?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Neil</description>
    <pubDate>Wed, 21 Apr 2010 13:49:28 GMT</pubDate>
    <dc:creator>Mirisage</dc:creator>
    <dc:date>2010-04-21T13:49:28Z</dc:date>
    <item>
      <title>creating a new variable with some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75970#M22051</link>
      <description>Hi colleagues,&lt;BR /&gt;
I have a data set (10,000 obs) like this .&lt;BR /&gt;
&lt;BR /&gt;
Data MDI;&lt;BR /&gt;
Input ID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10; /*ID=Household ID*/&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1 2 2 1 2 1 2 1 1 1 &lt;BR /&gt;
2 2 2 2 1 1 1 1 1 1 1&lt;BR /&gt;
3 1 1 1 1 1 1 1 1 2 1&lt;BR /&gt;
;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
I need to create a new variable called deprived where deprived=1 if you get two or more 2 s for variables Q1 to Q10, else deprived =2&lt;BR /&gt;
&lt;BR /&gt;
For instance, the new variable deprived for these three households should get following values:&lt;BR /&gt;
&lt;BR /&gt;
For first household, deprived =1 (because there are four 2 s)&lt;BR /&gt;
For second household, deprived =1 (because there are three 2 s)&lt;BR /&gt;
For third household, deprived =2 (because there is only one 2 )&lt;BR /&gt;
&lt;BR /&gt;
Could you please help me know with the codes to create the new variable called deprived?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Neil</description>
      <pubDate>Wed, 21 Apr 2010 13:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75970#M22051</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-21T13:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable with some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75971#M22052</link>
      <description>Neil&lt;BR /&gt;
&lt;BR /&gt;
Your sample shows only the values '1' or '2' for the q variables. If this is true then the following should work:&lt;BR /&gt;
&lt;BR /&gt;
if sum(of q:)&amp;gt;=12 then deprived=2;&lt;BR /&gt;
else deprived=1;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Wed, 21 Apr 2010 14:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75971#M22052</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-04-21T14:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable with some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75972#M22053</link>
      <description>concatenate, compress, count, test&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   deprived = ifN(lengthN(compress(cats(of q:),'2','K')) ge 2,1,2);&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 21 Apr 2010 14:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75972#M22053</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-21T14:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: creating a new variable with some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75973#M22054</link>
      <description>Hi Patrick, &lt;BR /&gt;
&lt;BR /&gt;
Your codes worked perfectly. Many thanks. &lt;BR /&gt;
&lt;BR /&gt;
However, I couldn't mention that some households responded for Q variables like this:&lt;BR /&gt;
Don’t know or Refused or Not stated.&lt;BR /&gt;
The codes for above three responses are 7, 8 and 9 respectively.&lt;BR /&gt;
&lt;BR /&gt;
In that case, how could I handle this situation? &lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Neil</description>
      <pubDate>Wed, 21 Apr 2010 14:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-a-new-variable-with-some-conditions/m-p/75973#M22054</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-21T14:48:50Z</dc:date>
    </item>
  </channel>
</rss>

