<?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: How do I create new indicator variables in a dataset based on variables from a second dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/293243#M311775</link>
    <description>Thank you both! Using sql to create a new transposed dataset 1 worked. I was trying to avoid that initially since my data set was very large, but in the end it was easiest to code.</description>
    <pubDate>Mon, 22 Aug 2016 19:54:11 GMT</pubDate>
    <dc:creator>ly2105</dc:creator>
    <dc:date>2016-08-22T19:54:11Z</dc:date>
    <item>
      <title>How do I create new indicator variables in a dataset based on variables from a second dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292846#M311771</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Dataset 1 is a discharge dataset. Each obsercation has a unique id (var name "ID") and10 diagnosis variables (var names dx_1, dx_2, dx_3, etc). The diagnosis variable values are ICD9 codes such as 707.00, 707.01, etc. &amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Dataset 2 contains a list of ICD9 codes and group-level variables. So, for each ICD9 code (unique, 1 observation each), I have 6 1/0 variables that indicate if the code is part of a larger group (var names group_1, group_2). I.e., ICD9 code 707.00 will get a "1" for group_1.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to be able to go through dataset 1, and look at each dx_n variable. If the value is, for example, 707.00, I want to assign that discharge a "1" for the variable group_1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I want to create these new indicator variables in dataset 1, but I am defining them based on group definitions from dataset 2. Should I do this in a datastep? Is there a SAS procedure that would make this easier?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 20:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292846#M311771</guid>
      <dc:creator>ly2105</dc:creator>
      <dc:date>2016-08-19T20:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create new indicator variables in a dataset based on variables from a second dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292847#M311772</link>
      <description>&lt;P&gt;Can you show a bit of your example data sets and what the output should actually look like.&lt;/P&gt;
&lt;P&gt;If the data in your dataset 2 is appropriate then it may be possible to create a group of informats that might terribly simplify and comparison syntax.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 20:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292847#M311772</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-19T20:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create new indicator variables in a dataset based on variables from a second dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292874#M311773</link>
      <description>&lt;P&gt;Would you feel comfortable transforming your second data set so that it ends up with just two variables: &amp;nbsp;ICD9 and group (taking on values from 1 through 6). That would be step 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next step would be to use that version of the data to create a format, and then applying the format to the first data set. &amp;nbsp;I just wasn't sure if you would need help with step 1.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2016 01:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292874#M311773</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-20T01:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create new indicator variables in a dataset based on variables from a second dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292878#M311774</link>
      <description>&lt;P&gt;Dealing with wide data structures involves more complications. Here is a way to get there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data d1;
input id (dx_1-dx_3) (:$8.);
datalines;
1 707.00 707.01 707.02
2 707.00 707.04 .
;

data d2;
input diag :$8. group_1-group_6;
datalines;
707.00 1 0 0 0 0 0
707.01 1 0 0 0 0 1
707.02 0 0 0 1 0 0
707.03 1 0 1 0 0 0
707.04 1 0 1 0 0 0
;

proc transpose data=d1 out=d1List;
by id;
var dx:;
run;

proc sql;
create table d1Groups as
select 
    d1List.id,
    d1List._name_, 
    d2.*
from 
    d1List left join 
    d2 on d1List.col1 = d2.diag
order by id, _name_;

create table diagList as
select 
    id, 
    _name_,
    diag,
    max(group_1) as group_1,
    max(group_2) as group_2,
    max(group_3) as group_3,
    max(group_4) as group_4,
    max(group_5) as group_5,
    max(group_6) as group_6
from d1Groups
group by id;
quit;

proc transpose data=diagList out=want(drop=_name_);
by id group_:;
id _name_;
var diag;
run;

proc print data=want noobs; 
var id dx_: group_:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Aug 2016 02:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/292878#M311774</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-20T02:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create new indicator variables in a dataset based on variables from a second dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/293243#M311775</link>
      <description>Thank you both! Using sql to create a new transposed dataset 1 worked. I was trying to avoid that initially since my data set was very large, but in the end it was easiest to code.</description>
      <pubDate>Mon, 22 Aug 2016 19:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-new-indicator-variables-in-a-dataset-based-on/m-p/293243#M311775</guid>
      <dc:creator>ly2105</dc:creator>
      <dc:date>2016-08-22T19:54:11Z</dc:date>
    </item>
  </channel>
</rss>

