<?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: Creation of a New Variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76025#M22073</link>
    <description>[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 20:51:24 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-04-21T20:51:24Z</dc:date>
    <item>
      <title>Creation of a New Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76024#M22072</link>
      <description>Hello colleagues,&lt;BR /&gt;
I have over 10,000 data set related to Material Deprivation like this .&lt;BR /&gt;
&lt;BR /&gt;
Data MD;&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   2 2 1 1  7 8 9 1 1 9 &lt;BR /&gt;
2   2 2 2 1 1 1 1 7 8 9 &lt;BR /&gt;
3   7 8 9 7 8 9 7 8 9  2 &lt;BR /&gt;
4   1 1 1 1 1 1 1 1 1 1 &lt;BR /&gt;
;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
Note: Responses 7, 8, and 9 are don’t know, refusal and not stated respectively.&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 a given household across variables Q1 to Q10, else deprived =2&lt;BR /&gt;
&lt;BR /&gt;
For instance, the new variable deprived for these four households should get following values:&lt;BR /&gt;
&lt;BR /&gt;
For first household, deprived =1 (because there are two ‘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;
For third household, deprived =2 (because there are no “two or more ‘2’ s”)&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 20:29:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76024#M22072</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-21T20:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of a New Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76025#M22073</link>
      <description>[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 20:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76025#M22073</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-21T20:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of a New Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76026#M22074</link>
      <description>My idea is :&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
  set md;&lt;BR /&gt;
  index=1*(Q1=2)+1*(Q2=2)+1*(Q3=2)+1*(Q4=2)+1*(Q5=2)+1*(Q6=2)+1*(Q7=2)+1*(Q8=2)+1*(Q9=2)+1*(Q10=2);&lt;BR /&gt;
  if index ge 2 then deprived=1;&lt;BR /&gt;
     else deprived=2;&lt;BR /&gt;
  drop index;&lt;BR /&gt;
run;

Message was edited by: Ksharp</description>
      <pubDate>Thu, 22 Apr 2010 09:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76026#M22074</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-04-22T09:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of a New Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76027#M22075</link>
      <description>Many thanks for this code which works nicely.&lt;BR /&gt;
&lt;BR /&gt;
Neil</description>
      <pubDate>Fri, 23 Apr 2010 15:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76027#M22075</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-23T15:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of a New Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76028#M22076</link>
      <description>Mirisage&lt;BR /&gt;
&lt;BR /&gt;
glad you've got a solution.&lt;BR /&gt;
For brevity, consider [pre]&lt;BR /&gt;
  deprived = 2-( count( cats(of q1-q10), '2' ) &amp;gt;1 ) ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
the count() function will return the number of '2' in the concatenation of Q1-Q10 .&lt;BR /&gt;
The logical test {that count} &amp;gt;1 returns 1 when there are 2 or more 2s, and 0 otherwise.</description>
      <pubDate>Mon, 26 Apr 2010 08:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76028#M22076</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-04-26T08:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of a New Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76029#M22077</link>
      <description>Hi Ksharp &amp;amp; Peter,&lt;BR /&gt;
&lt;BR /&gt;
Thank both of you. These different approaches are very helpful. And  Peter's accompanying text is very helpful.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Neil</description>
      <pubDate>Mon, 26 Apr 2010 16:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creation-of-a-New-Variable/m-p/76029#M22077</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-04-26T16:52:24Z</dc:date>
    </item>
  </channel>
</rss>

