<?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 using first. with multiple by variables and assigning a value in new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/432986#M107294</link>
    <description>&lt;P&gt;I have a data set like following&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;informat date1 date9.;&lt;BR /&gt;format date1 date9.;&lt;BR /&gt;input date1 id flag$;&lt;BR /&gt;cards;&lt;BR /&gt;21jan2018 1 n&lt;BR /&gt;21jan2018 1 y&lt;BR /&gt;21jan2018 1 y&lt;BR /&gt;22jan2018 1 y&lt;BR /&gt;22jan2018 1 y&lt;BR /&gt;22jan2018 1 y&lt;BR /&gt;22jan2018 2 n&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I want to add a flag1 such that same date and same id flag1 will take value of flag and retain that value for same date and id.&lt;/P&gt;&lt;P&gt;once id got change in same date then flag 1 should have value of flag and retain that value for same date and id&lt;/P&gt;&lt;P&gt;once date gets changes again code should assign value of flag to flag1 and retain that value for date and id&lt;/P&gt;&lt;P&gt;I want an output like following&lt;/P&gt;&lt;P&gt;Date ID Flag Flag1&lt;/P&gt;&lt;P&gt;21jan2018 1 n n&lt;BR /&gt;21jan2018 1 y n&lt;BR /&gt;21jan2018 1 y n&lt;BR /&gt;22jan2018 1 y y&lt;BR /&gt;22jan2018 1 y y&lt;BR /&gt;22jan2018 1 y y&lt;BR /&gt;22jan2018 2 n n&lt;BR /&gt;22jan2018 2 y n&lt;BR /&gt;22jan2018 2 y n&lt;BR /&gt;22jan2018 2 y n&lt;BR /&gt;22jan2018 2 y n&lt;/P&gt;&lt;P&gt;I tried using following code but not successful.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set test;&lt;BR /&gt;by date1 id flag;&lt;BR /&gt;retain flag1;&lt;BR /&gt;if first.date1&amp;nbsp; then do;&lt;BR /&gt;if first.id then do;&lt;BR /&gt;if flag ne "n" then flag1 = "y";&lt;BR /&gt;else if flag eq "n" then flag1 = "n";&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;please help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;VR&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 03:24:13 GMT</pubDate>
    <dc:creator>V_R</dc:creator>
    <dc:date>2018-02-01T03:24:13Z</dc:date>
    <item>
      <title>using first. with multiple by variables and assigning a value in new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/432986#M107294</link>
      <description>&lt;P&gt;I have a data set like following&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;informat date1 date9.;&lt;BR /&gt;format date1 date9.;&lt;BR /&gt;input date1 id flag$;&lt;BR /&gt;cards;&lt;BR /&gt;21jan2018 1 n&lt;BR /&gt;21jan2018 1 y&lt;BR /&gt;21jan2018 1 y&lt;BR /&gt;22jan2018 1 y&lt;BR /&gt;22jan2018 1 y&lt;BR /&gt;22jan2018 1 y&lt;BR /&gt;22jan2018 2 n&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;22jan2018 2 y&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I want to add a flag1 such that same date and same id flag1 will take value of flag and retain that value for same date and id.&lt;/P&gt;&lt;P&gt;once id got change in same date then flag 1 should have value of flag and retain that value for same date and id&lt;/P&gt;&lt;P&gt;once date gets changes again code should assign value of flag to flag1 and retain that value for date and id&lt;/P&gt;&lt;P&gt;I want an output like following&lt;/P&gt;&lt;P&gt;Date ID Flag Flag1&lt;/P&gt;&lt;P&gt;21jan2018 1 n n&lt;BR /&gt;21jan2018 1 y n&lt;BR /&gt;21jan2018 1 y n&lt;BR /&gt;22jan2018 1 y y&lt;BR /&gt;22jan2018 1 y y&lt;BR /&gt;22jan2018 1 y y&lt;BR /&gt;22jan2018 2 n n&lt;BR /&gt;22jan2018 2 y n&lt;BR /&gt;22jan2018 2 y n&lt;BR /&gt;22jan2018 2 y n&lt;BR /&gt;22jan2018 2 y n&lt;/P&gt;&lt;P&gt;I tried using following code but not successful.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;set test;&lt;BR /&gt;by date1 id flag;&lt;BR /&gt;retain flag1;&lt;BR /&gt;if first.date1&amp;nbsp; then do;&lt;BR /&gt;if first.id then do;&lt;BR /&gt;if flag ne "n" then flag1 = "y";&lt;BR /&gt;else if flag eq "n" then flag1 = "n";&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;please help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;VR&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 03:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/432986#M107294</guid>
      <dc:creator>V_R</dc:creator>
      <dc:date>2018-02-01T03:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: using first. with multiple by variables and assigning a value in new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/432989#M107295</link>
      <description>&lt;P&gt;All you need is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
set test;
by date1 id;
retain flag1;
if first.id then flag1 = flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;first.id is = 1 whenever&amp;nbsp;date1 OR id changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 04:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/432989#M107295</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-02-05T04:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: using first. with multiple by variables and assigning a value in new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/434039#M107688</link>
      <description>&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 03:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-first-with-multiple-by-variables-and-assigning-a-value-in/m-p/434039#M107688</guid>
      <dc:creator>V_R</dc:creator>
      <dc:date>2018-02-05T03:15:30Z</dc:date>
    </item>
  </channel>
</rss>

