<?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 new columns(Alternatives) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35111#M8617</link>
    <description>To me the data structure not optimal.  I would expect the patients to have varying number of diseases so a verticle structure is preferred.  You can flattin it at any time if need.  &lt;BR /&gt;
&lt;BR /&gt;
An INFORMAT makes a nice lookup table in this situation where you want to read a code and create a numeric value.  &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   invalue disease(upcase just)&lt;BR /&gt;
      'I21','I71','K27','G450' = 1&lt;BR /&gt;
      'E102','G81' = 2&lt;BR /&gt;
      'C80','C77'  = 3&lt;BR /&gt;
      'B20' = 6&lt;BR /&gt;
      ;&lt;BR /&gt;
   run;&lt;BR /&gt;
data disease;&lt;BR /&gt;
   infile cards missover column=c;&lt;BR /&gt;
   input patient @;&lt;BR /&gt;
   do while(1);&lt;BR /&gt;
      _iorc_ = c;&lt;BR /&gt;
      input disease :$4. @;&lt;BR /&gt;
      if missing(disease) then leave;&lt;BR /&gt;
      input +(-(c-_iorc_)) weight :disease. @;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1 I21 E102 C80&lt;BR /&gt;
2 B20 C77 G81 E102&lt;BR /&gt;
3 B20 K27 G450&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc summary data=disease nway;&lt;BR /&gt;
   class patient;&lt;BR /&gt;
   output out=wide(drop=_:) &lt;BR /&gt;
      sum(weight)= &lt;BR /&gt;
      idgroup(out[4](disease weight)=)&lt;BR /&gt;
      ;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Mon, 14 Jun 2010 14:24:32 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-06-14T14:24:32Z</dc:date>
    <item>
      <title>Creating new columns(Alternatives)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35109#M8615</link>
      <description>I have data in the following format: It consists of patients and the numbers of diseases each patient experienced. &lt;BR /&gt;
&lt;BR /&gt;
patient disease1 disease2 disease3;&lt;BR /&gt;
1          I21          E102           C80&lt;BR /&gt;
2          B20      C77         G81&lt;BR /&gt;
3         B20         K27         G450&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I then assign weight to each disease using the following codes; The intention is to come up with total burden of the diseases. For example in patient1 I will add  the weights of I21, E102 and C80. In partient2 I will add the weights of B20 C77 G81, and etc. I used the following codes to create the three columns and then add across the new three columns.&lt;BR /&gt;
&lt;BR /&gt;
If disease1 = 'I21' then do;&lt;BR /&gt;
weight1 = 1;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease1 = 'B20' then do;&lt;BR /&gt;
weight1 = 6;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease2 = 'I71' then do;&lt;BR /&gt;
weight2 = 1;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease2 = 'E102' then do;&lt;BR /&gt;
weight2 = 2;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease2 = 'C77' then do;&lt;BR /&gt;
weight2 = 3;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease2 = 'K27' then do;&lt;BR /&gt;
weight2 = 1;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease3 = 'C80' then do;&lt;BR /&gt;
weight3 = 3;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease3 = 'G81' then do;&lt;BR /&gt;
weight3 = 2;&lt;BR /&gt;
end;&lt;BR /&gt;
else if disease3 = 'G450' then do;&lt;BR /&gt;
weight3 = 1;&lt;BR /&gt;
end;&lt;BR /&gt;
RUN;&lt;BR /&gt;
WEIGHT = weight1 + weight + weight3;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Finally the data will be of the following format&lt;BR /&gt;
&lt;BR /&gt;
Patient Disease1 disease2 disease3  weight1 weight2 weight3 weight&lt;BR /&gt;
1          I21          E102           C80      1            2             3      6&lt;BR /&gt;
2          B20      C77         G81            6            3             2       11 &lt;BR /&gt;
3         B20         K27         G450        6             1            1        8&lt;BR /&gt;
run;&lt;BR /&gt;
 I was wondering if there is any other way of creating the new columns beside using the procedure that I have used. The problem with the procedure that I have used is that it can be a lot of work if patients have many diseases involved. Can someone help me.</description>
      <pubDate>Mon, 14 Jun 2010 09:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35109#M8615</guid>
      <dc:creator>Statsconsultancy</dc:creator>
      <dc:date>2010-06-14T09:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns(Alternatives)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35110#M8616</link>
      <description>Several.&lt;BR /&gt;
1.  Create a format then  weight1= input(put(disease1, $newfmt.), best.);&lt;BR /&gt;
2. Create a lookup table with disease, and weight then do 3 set statements with a "KEY".&lt;BR /&gt;
3. Create a lookup table then with SQL  create columns as a.weight as weight1, b.weight as weight2, c.weight as weight3 from olddata o, &lt;BR /&gt;
left join lookup a on o.disease1 = a.disease&lt;BR /&gt;
left join lookup b on o.disease2 = b.disease&lt;BR /&gt;
left join lookup c on o.disease3 = c.disease</description>
      <pubDate>Mon, 14 Jun 2010 11:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35110#M8616</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-06-14T11:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns(Alternatives)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35111#M8617</link>
      <description>To me the data structure not optimal.  I would expect the patients to have varying number of diseases so a verticle structure is preferred.  You can flattin it at any time if need.  &lt;BR /&gt;
&lt;BR /&gt;
An INFORMAT makes a nice lookup table in this situation where you want to read a code and create a numeric value.  &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   invalue disease(upcase just)&lt;BR /&gt;
      'I21','I71','K27','G450' = 1&lt;BR /&gt;
      'E102','G81' = 2&lt;BR /&gt;
      'C80','C77'  = 3&lt;BR /&gt;
      'B20' = 6&lt;BR /&gt;
      ;&lt;BR /&gt;
   run;&lt;BR /&gt;
data disease;&lt;BR /&gt;
   infile cards missover column=c;&lt;BR /&gt;
   input patient @;&lt;BR /&gt;
   do while(1);&lt;BR /&gt;
      _iorc_ = c;&lt;BR /&gt;
      input disease :$4. @;&lt;BR /&gt;
      if missing(disease) then leave;&lt;BR /&gt;
      input +(-(c-_iorc_)) weight :disease. @;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1 I21 E102 C80&lt;BR /&gt;
2 B20 C77 G81 E102&lt;BR /&gt;
3 B20 K27 G450&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc summary data=disease nway;&lt;BR /&gt;
   class patient;&lt;BR /&gt;
   output out=wide(drop=_:) &lt;BR /&gt;
      sum(weight)= &lt;BR /&gt;
      idgroup(out[4](disease weight)=)&lt;BR /&gt;
      ;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 14 Jun 2010 14:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35111#M8617</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-06-14T14:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns(Alternatives)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35112#M8618</link>
      <description>Hi. data null;'s code is too difficulty to me .&lt;BR /&gt;
But I agree with Flip's suggestion.&lt;BR /&gt;
You can create three format for three disease variables.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Tue, 15 Jun 2010 06:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-new-columns-Alternatives/m-p/35112#M8618</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-15T06:44:32Z</dc:date>
    </item>
  </channel>
</rss>

