<?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: Logic to create new variable based on data in multiple rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687259#M208619</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    merge have(where=(recordno=1)) have(where=(recordno=2)
        rename=(season=season2 gasyear=gasyear2));
   by id;
   if season='Summer' and season2='Summer' and gasyear=gasyear2 then flag=1;
   else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assumes the input data is properly sorted by ID, and that there really are only two records per ID.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 15:57:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-28T15:57:43Z</dc:date>
    <item>
      <title>Logic to create new variable based on data in multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687236#M208615</link>
      <description>&lt;P&gt;&lt;STRONG&gt;ID season gasyear recordno&lt;/STRONG&gt;&lt;BR /&gt;2401562901 Summer 19/20 1&lt;BR /&gt;2401562901 Winter 19/20 2&lt;BR /&gt;2401564310 Summer 19/20 1&lt;BR /&gt;2401564310 Summer 19/20 2&lt;BR /&gt;2402213802 Summer 19/20 1&lt;BR /&gt;2402213802 Summer 19/20 2&lt;BR /&gt;2402412909 Summer 19/20 1&lt;BR /&gt;2402412909 Summer 19/20 2&lt;BR /&gt;2416061809 Winter 19/20 1&lt;BR /&gt;2416061809 Summer 18/19 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to create a column based on the following rules:&lt;/P&gt;
&lt;P&gt;it needs to look at each unique ID (there are only 2 rows per id).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is the season for record 1 'Summer'&lt;STRONG&gt; and&lt;/STRONG&gt; season for record 2 'Summer'&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;and&lt;/STRONG&gt;&lt;/U&gt; are the gasyear for record 1 &lt;STRONG&gt;and&lt;/STRONG&gt; record 2 the same&lt;/P&gt;
&lt;P&gt;if so it would give a flag 'Y' else 'N'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried coding a few options and they don't work&lt;/P&gt;
&lt;P&gt;i tired the lag function but it doesn't work when going on to a new id&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687236#M208615</guid>
      <dc:creator>mpangli</dc:creator>
      <dc:date>2020-09-28T15:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Logic to create new variable based on data in multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687259#M208619</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    merge have(where=(recordno=1)) have(where=(recordno=2)
        rename=(season=season2 gasyear=gasyear2));
   by id;
   if season='Summer' and season2='Summer' and gasyear=gasyear2 then flag=1;
   else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assumes the input data is properly sorted by ID, and that there really are only two records per ID.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687259#M208619</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-28T15:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Logic to create new variable based on data in multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687261#M208620</link>
      <description>&lt;P&gt;It can be done with &lt;STRONG&gt;do until()&lt;/STRONG&gt; loops:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
flag = "Y";
do until(last.ID);
    set have; by ID;
    if season ne "Summer" then flag = "N";
    if missing(gy) then gy = gasyear;
    else if gy ne gasyear then flag = "N";
    end;
do until(last.ID);
    set have; by ID;
    output;
    end;
drop gy;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-create-new-variable-based-on-data-in-multiple-rows/m-p/687261#M208620</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-28T16:00:51Z</dc:date>
    </item>
  </channel>
</rss>

