<?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: set by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922997#M363399</link>
    <description>&lt;P&gt;What is it that you are trying to flag?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have four observations that you are ordering by two variables.&lt;/P&gt;
&lt;PRE&gt;       anagrafica_    dt_denuncia_
Obs    soggetto_id         id

 1         4312        2015-06-22
 2         4312        2016-02-23
 3         4312        2021-05-24
 4        25632        2016-06-16

&lt;/PRE&gt;
&lt;P&gt;Observation 1 is the first since it is the first observation overall.&lt;/P&gt;
&lt;P&gt;Observation 2 is the first since the value of the second variable changes.&lt;/P&gt;
&lt;P&gt;Observation 3 is the first since the value of the second variable changes.&lt;/P&gt;
&lt;P&gt;Observation 4 is the first since the value of the first variable changes.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Apr 2024 15:14:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-04-04T15:14:28Z</dc:date>
    <item>
      <title>set by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922995#M363398</link>
      <description>&lt;DIV class="QFw9Te BLojaf"&gt;
&lt;DIV id="ow351"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="QcsUad BDJ8fb BLojaf sMVRZe wneUed"&gt;
&lt;DIV class="usGWQd"&gt;
&lt;DIV class="KkbLmb"&gt;
&lt;DIV class="lRu31" dir="ltr"&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Good morning.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;I can't understand why from this code the result on table "out" of first_unique is always 1&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="lRu31" dir="ltr"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp1;
input anagrafica_soggetto_id dt_denuncia_id :ddmmyy10.;
format dt_denuncia_id ddmmyy10.;
datalines;
25632 16/06/2016
4312 22/06/2015
4312 23/02/2016
4312 24/05/2021
run;
proc sort data=tmp1;
by ANAGRAFICA_SOGGETTO_ID dt_denuncia_id ;
run;
data out;
set tmp1;
by ANAGRAFICA_SOGGETTO_ID dt_denuncia_id ;
if first.dt_denuncia_id then first_unique = 1;
else first_unique = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="HwtZe"&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Using set + by I would expect this result:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;4312 22/06/2015 1&lt;BR /&gt;4312 23/02/2016 1&lt;BR /&gt;4312 24/05/2021 0&lt;BR /&gt;25632 16/06/2016 0&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 14:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922995#M363398</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2024-04-04T14:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: set by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922997#M363399</link>
      <description>&lt;P&gt;What is it that you are trying to flag?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have four observations that you are ordering by two variables.&lt;/P&gt;
&lt;PRE&gt;       anagrafica_    dt_denuncia_
Obs    soggetto_id         id

 1         4312        2015-06-22
 2         4312        2016-02-23
 3         4312        2021-05-24
 4        25632        2016-06-16

&lt;/PRE&gt;
&lt;P&gt;Observation 1 is the first since it is the first observation overall.&lt;/P&gt;
&lt;P&gt;Observation 2 is the first since the value of the second variable changes.&lt;/P&gt;
&lt;P&gt;Observation 3 is the first since the value of the second variable changes.&lt;/P&gt;
&lt;P&gt;Observation 4 is the first since the value of the first variable changes.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 15:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922997#M363399</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-04T15:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: set by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922999#M363401</link>
      <description>&lt;P&gt;When in doubt look at the actual values of all of the first and last variables created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data out;
   set tmp1;
   by ANAGRAFICA_SOGGETTO_ID dt_denuncia_id ;
   ANAGRAFICA_byfirst = first.ANAGRAFICA_SOGGETTO_ID;
   ANAGRAFICA_bylast  = last.ANAGRAFICA_SOGGETTO_ID;
   denuncia_byfirst   = first.dt_denuncia_id ;
   denuncia_bylast    = last.dt_denuncia_id ;

run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2024 15:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-by/m-p/922999#M363401</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-04T15:26:05Z</dc:date>
    </item>
  </channel>
</rss>

