<?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 with by and if clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807013#M318076</link>
    <description>&lt;P&gt;This is a particularly poor example, as the IN operator is called and creates variables, but the variables created are not used. So they have no purpose here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any event, the SAS documentation explains it all:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/ledsoptsref/n1p1o2dsuc465nn198ovwdrj9mvy.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/ledsoptsref/n1p1o2dsuc465nn198ovwdrj9mvy.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Apr 2022 12:40:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-04-10T12:40:33Z</dc:date>
    <item>
      <title>Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807010#M318073</link>
      <description>&lt;P&gt;I'm trying to understand the program which was written by other programmer. In the below code, I don't understand the purpose of IN operator.&lt;BR /&gt;Any help to make me understand this code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
set have1(in=a) have2(in=b);
by id name;
if dt=. then dt=start_dt;
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Apr 2022 12:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807010#M318073</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-04-10T12:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807013#M318076</link>
      <description>&lt;P&gt;This is a particularly poor example, as the IN operator is called and creates variables, but the variables created are not used. So they have no purpose here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any event, the SAS documentation explains it all:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/ledsoptsref/n1p1o2dsuc465nn198ovwdrj9mvy.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/ledsoptsref/n1p1o2dsuc465nn198ovwdrj9mvy.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 12:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807013#M318076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-10T12:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807046#M318087</link>
      <description>&lt;P&gt;The IN= dataset option (the IN operator is a totally different concept and does not appear in this program) is doing no good in that program.&amp;nbsp; And it might be doing harm if either HAVE1 or HAVE2 have variables names A or B already. The purpose of the IN= dataset option is to name a numeric variable that SAS will set TRUE when that dataset contributed to the current observation.&amp;nbsp; But this data step is not using those variables for anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step is interleaving the observations from HAVE1 and HAVE2 so that the resulting WANT dataset will still be sorted by ID and NAME.&lt;/P&gt;
&lt;P&gt;The IF/THEN statement is replacing missing DT values with value of DT_START.&amp;nbsp; You could have instead used the COALESE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have1 have2;
  by id name;
  dt=coalesce(dt,start_dt);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 17:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807046#M318087</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-10T17:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807048#M318089</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;So in my example, it's just appending the HAVE1 and HAVE2 dataset and then applying IF clause? I just trying to understand the code which I posted.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 17:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807048#M318089</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-04-10T17:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807049#M318090</link>
      <description>&lt;P&gt;Not APPENDING. It is INTERLEAVING the observations from both datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you remove the BY statement then it would be APPENDING.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 17:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807049#M318090</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-10T17:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807051#M318092</link>
      <description>Interleaving is similar to inner join?&lt;BR /&gt;</description>
      <pubDate>Sun, 10 Apr 2022 17:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807051#M318092</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-04-10T17:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807056#M318096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Interleaving is similar to inner join?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&amp;nbsp; An inner join is more like a MERGE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you ever tried to sort something that was too big to sort all at once? So you break it into smaller piles and sort each one.&amp;nbsp; Now you can make your final output by just taking from the top of each smaller pile by checking which pile has the smallest value on the top.&amp;nbsp; That is interleaving.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or kind of like shuffling a deck of cards.&amp;nbsp; Only with some smarts so the result is still sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do your own experiment. Take a decks of cards.&amp;nbsp; Take some HEARTS and some SPADES and make two piles based on suit.&amp;nbsp; Sort each pile so they are face up with the smallest on the top.&amp;nbsp; Now make a new stack face down by taking the smallest card from the top of the two stacks. When they are the same value take the HEART one first.&amp;nbsp; The result is an ordered set of cards.&amp;nbsp; When there is a tie in value the HEART is always before the SPADE.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 18:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/807056#M318096</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-10T18:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808029#M318609</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Were you able to point me to one SAS program example which use SET with BY for interleaving? I use first. and last. whenever I use set with by. Posted example was written by other progarmmer&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2022 15:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808029#M318609</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-04-15T15:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808095#M318644</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Were you able to point me to one SAS program example which use SET with BY for interleaving? I use first. and last. whenever I use set with by. Posted example was written by other progarmmer&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data boys (where=(sex='M'))
     girls (where=(sex='F'));
  set sashelp.class;
run;

data interleaved;
  set boys girls;
  by name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above works because sashelp.class&amp;nbsp; (and therefore BOYS and GIRLS) is sorted by NAME.&amp;nbsp; As a consequence dataset INTERLEAVED is sorted by name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without the BY statement, you would get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_boys_followed_by_all_girls;
  set boys girls;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Apr 2022 21:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808095#M318644</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-15T21:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808138#M318648</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What interleaving is and how it works is explained in the SAS documentation &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n0ne6ix34pcmizn1abmzu7285ed1.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;This is a sub-chapter of&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p10anaj99ur4s6n1xof3h30pvdlz.htm" target="_self"&gt;Combining Data&lt;/A&gt;. May-be worth that you read this chapter from start to end.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2022 01:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808138#M318648</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-04-16T01:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Set with by and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808143#M318653</link>
      <description>&lt;P&gt;See this simple example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input val;
datalines;
1
3
5
;

data b;
input val;
datalines;
2
4
6
;

data interleave;
set
  a
  b
;
by val;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will find that the resulting dataset is neatly ordered in sequence 1 - 2 - 3 - 4 - 5 - 6.&lt;/P&gt;
&lt;P&gt;Play around with the values in the datasets to see how the interleave works&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;multiple entries in one or both datasets&lt;/LI&gt;
&lt;LI&gt;identical entries in both datasets&lt;/LI&gt;
&lt;LI&gt;see what you can do with IN= dataset options&lt;/LI&gt;
&lt;LI&gt;explore the behavior of FIRST. and LAST.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Sat, 16 Apr 2022 08:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-with-by-and-if-clause/m-p/808143#M318653</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-16T08:28:12Z</dc:date>
    </item>
  </channel>
</rss>

