<?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: New Variable combining several codes in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31513#M7508</link>
    <description>DATA FAMILY_1;&lt;BR /&gt;
SET FAMILY;&lt;BR /&gt;
IF Family_type IN (2,3,4) THEN TYPE=4;&lt;BR /&gt;
ELSE TYPE=Family_type;&lt;BR /&gt;
RUN;</description>
    <pubDate>Tue, 08 Jun 2010 08:20:33 GMT</pubDate>
    <dc:creator>dhana</dc:creator>
    <dc:date>2010-06-08T08:20:33Z</dc:date>
    <item>
      <title>New Variable combining several codes</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31508#M7503</link>
      <description>Hi Colleagues,&lt;BR /&gt;
&lt;BR /&gt;
Would appreciate if anyone of you could help on this.&lt;BR /&gt;
&lt;BR /&gt;
I have 7000 observations like this.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data Family;&lt;BR /&gt;
input ID Family_type;&lt;BR /&gt;
cards;&lt;BR /&gt;
1	1	&lt;BR /&gt;
2	1	&lt;BR /&gt;
3	1	&lt;BR /&gt;
4	2	&lt;BR /&gt;
5	3	&lt;BR /&gt;
6	4	&lt;BR /&gt;
7	6	&lt;BR /&gt;
8	5	&lt;BR /&gt;
9	6	&lt;BR /&gt;
10	4	&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I need to create a new variable called ‘Type’ using the existing variable ‘Family_type’.&lt;BR /&gt;
&lt;BR /&gt;
Condition is: &lt;BR /&gt;
If Family_type = 2 or 3 or 4, Type = 4&lt;BR /&gt;
All other codes of ‘Family_type’ variable should remain the same for newly created ‘Type’ variable too.&lt;BR /&gt;
&lt;BR /&gt;
I tried the following but did not work.&lt;BR /&gt;
&lt;BR /&gt;
data Family_1;&lt;BR /&gt;
set Family;&lt;BR /&gt;
if Family_type = 2 or Family_type = 3 or Family_type = 4 then Type = 4 ;&lt;BR /&gt;
if Family_type = 1 then Type = 1;&lt;BR /&gt;
if Family_type = 5 then Type = 5;&lt;BR /&gt;
else Type = 6;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I would appreciate if you could help me.&lt;BR /&gt;
Thank you&lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
      <pubDate>Fri, 04 Jun 2010 11:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31508#M7503</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-06-04T11:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: New Variable combining several codes</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31509#M7504</link>
      <description>The problem is your last if/else code:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if Family_type = 5 then Type = 5;&lt;BR /&gt;
else Type = 6;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
The else-part sets Type = 6 if Family_type != 5. Try following &lt;B&gt;untested&lt;/B&gt; code skips checking the value of Family_type if Type equals Family_type.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data Family_1;&lt;BR /&gt;
  set Family;&lt;BR /&gt;
  if Family_type = 2 or Family_type = 3 or Family_type = 4 then Type = 4;&lt;BR /&gt;
  else Type = Family_type;&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
The if-statement can be made easier to understand by using the in-operator:&lt;BR /&gt;
[pre]...&lt;BR /&gt;
if Family_type in (2, 3) then Type = 4;&lt;BR /&gt;
else Type = Family_type;&lt;BR /&gt;
...[/pre]</description>
      <pubDate>Fri, 04 Jun 2010 11:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31509#M7504</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2010-06-04T11:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: New Variable combining several codes</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31510#M7505</link>
      <description>Check for missing "ELSE" operator in some of your IF / THEN statements.  &lt;BR /&gt;
&lt;BR /&gt;
A useful debugging technique when desk-checking your program is to insert the statement below which will generate additional diagnostic information (about variable values) along the course of your DATA step (increment "nn" below when you have multiple of these lines in your program for identification):&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG '&amp;gt;DIAG-nn&amp;gt;' / _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 04 Jun 2010 11:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31510#M7505</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-06-04T11:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: New Variable combining several codes</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31511#M7506</link>
      <description>Try this.&lt;BR /&gt;
&lt;BR /&gt;
data Family_1;&lt;BR /&gt;
set Family;&lt;BR /&gt;
if Family_type=2 or Family_type=3 or Family_type=4 then Type=4 ;&lt;BR /&gt;
if Family_type= 1 then Type=1;&lt;BR /&gt;
if Family_type= 5 then Type=5;&lt;BR /&gt;
if type=. then type=Family_type;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 07 Jun 2010 08:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31511#M7506</guid>
      <dc:creator>sas_</dc:creator>
      <dc:date>2010-06-07T08:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: New Variable combining several codes</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31512#M7507</link>
      <description>Hi andreas_lds, sas_ and sbb,&lt;BR /&gt;
&lt;BR /&gt;
Thank all of you. All the codes suggested by you all worked quite well.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
      <pubDate>Mon, 07 Jun 2010 14:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31512#M7507</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-06-07T14:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: New Variable combining several codes</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31513#M7508</link>
      <description>DATA FAMILY_1;&lt;BR /&gt;
SET FAMILY;&lt;BR /&gt;
IF Family_type IN (2,3,4) THEN TYPE=4;&lt;BR /&gt;
ELSE TYPE=Family_type;&lt;BR /&gt;
RUN;</description>
      <pubDate>Tue, 08 Jun 2010 08:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/New-Variable-combining-several-codes/m-p/31513#M7508</guid>
      <dc:creator>dhana</dc:creator>
      <dc:date>2010-06-08T08:20:33Z</dc:date>
    </item>
  </channel>
</rss>

