<?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: Look at multiple observations to create a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823457#M325137</link>
    <description>&lt;P&gt;Assuming the data is grouped by name:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by name notsorted;

   length eligible 8 a_code $ 2;
   retain eligible a_code;

   if first.name then do;
      eligible = 1;
   end;

   if first(code) = 'A' then do;
      a_code = code;
   end;

   eligible = eligible and (first(code) not in ('B', 'C'));

   if last.name then do;
      code = a_code;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Jul 2022 04:49:24 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-07-15T04:49:24Z</dc:date>
    <item>
      <title>Look at multiple observations to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823452#M325133</link>
      <description>&lt;P&gt;I have a data set of patients and diagnosis codes, for example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name, code&lt;/P&gt;&lt;P&gt;Sarah, A1&lt;/P&gt;&lt;P&gt;Sarah, B1&lt;/P&gt;&lt;P&gt;Sarah, C1&lt;/P&gt;&lt;P&gt;Matt, A2&lt;/P&gt;&lt;P&gt;Matt, E2&lt;/P&gt;&lt;P&gt;Dave, A2&lt;/P&gt;&lt;P&gt;Dave, B3&lt;/P&gt;&lt;P&gt;Dave, E2&lt;/P&gt;&lt;P&gt;George, C2&lt;/P&gt;&lt;P&gt;George, A1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am screening the patients for a research study. They all have A1 or A2. If they also have a B code or C code, they are not eligible for the study. I want to create a set like the following that just has 1 entry for each patient with a new variable that says if they are eligible and the code variable should be their A code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name, code, eligible&lt;/P&gt;&lt;P&gt;Sarah, A1, no&lt;/P&gt;&lt;P&gt;Matt, A2, yes&lt;/P&gt;&lt;P&gt;Dave, A2, no&lt;/P&gt;&lt;P&gt;George, A1, no&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I look at each code and then create one observation with a new variable to say if the patient is eligible?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 03:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823452#M325133</guid>
      <dc:creator>lauraem93</dc:creator>
      <dc:date>2022-07-15T03:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Look at multiple observations to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823457#M325137</link>
      <description>&lt;P&gt;Assuming the data is grouped by name:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by name notsorted;

   length eligible 8 a_code $ 2;
   retain eligible a_code;

   if first.name then do;
      eligible = 1;
   end;

   if first(code) = 'A' then do;
      a_code = code;
   end;

   eligible = eligible and (first(code) not in ('B', 'C'));

   if last.name then do;
      code = a_code;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jul 2022 04:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823457#M325137</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-15T04:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Look at multiple observations to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823501#M325155</link>
      <description>&lt;PRE&gt;data have;
infile cards dlm=' ,';
input name $ code $;
cards;
Sarah, A1
Sarah, B1
Sarah, C1
Matt, A2
Matt, E2
Dave, A2
Dave, B3
Dave, E2
George, C2
George, A1
;

proc sql;
create table want as
select name,min(code) as code,
ifc(sum(code eqt 'B' or code eqt 'C'),'no ','yes' ) as eligible
 from have 
  group by name;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jul 2022 13:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-at-multiple-observations-to-create-a-new-variable/m-p/823501#M325155</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-07-15T13:08:38Z</dc:date>
    </item>
  </channel>
</rss>

