<?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: Need help for so proc sql step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334082#M75396</link>
    <description>Output looks great Chris. Thanks.&lt;BR /&gt;&lt;BR /&gt;Id is the primary key. Pay can be same or different. But wondering why we have to use min and max with Id and pay. If you could help me understand it please.&lt;BR /&gt;&lt;BR /&gt;Thanks again.</description>
    <pubDate>Sat, 18 Feb 2017 15:46:42 GMT</pubDate>
    <dc:creator>adityaa9z</dc:creator>
    <dc:date>2017-02-18T15:46:42Z</dc:date>
    <item>
      <title>Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334058#M75385</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are two datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input id act_no$ date date9. time TIME10. ;&lt;BR /&gt;cards;&lt;BR /&gt;1 trn1 13FEB2017 2.30am&lt;BR /&gt;2 trn1 14FEB2017 3.30am&lt;BR /&gt;3 trn2 13FEB2017 2.30am&lt;BR /&gt;4 trn3 14FEB2017 2.30am&lt;BR /&gt;5 trn3 13FEB2017 2.30am&lt;BR /&gt;6 trn3 13FEB2017 3.30pm&lt;BR /&gt;7 trn4 13FEB2017 5.30am&lt;BR /&gt;8 trn5 13FEB2017 6.30am&lt;BR /&gt;9 trn5 13FEB2017 6.30pm&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;input id pay dollar10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 10&lt;BR /&gt;2 20&lt;BR /&gt;3 20&lt;BR /&gt;4 40&lt;BR /&gt;5 50&lt;BR /&gt;6 60&lt;BR /&gt;7 70&lt;BR /&gt;8 80&lt;BR /&gt;9 90&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to see an output like&amp;nbsp;the one mentioned below.. So for the combination of act_no and date , only the first trn which happens within that date should be picked. I used the concept of left join along with group by but to no success. Can someone help out pls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 trn1 13FEB2017 2.30am 10&lt;BR /&gt;2 trn1 14FEB2017 3.30am 20&lt;BR /&gt;3 trn2 13FEB2017 2.30am 30&lt;BR /&gt;4 trn3 14FEB2017 2.30am 40&lt;BR /&gt;5 trn3 13FEB2017 2.30am 50&lt;BR /&gt;7 trn4 13FEB2017 5.30am 70&lt;BR /&gt;8 trn5 13FEB2017 6.30am 80&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2017 14:23:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334058#M75385</guid>
      <dc:creator>adityaa9z</dc:creator>
      <dc:date>2017-02-18T14:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334063#M75386</link>
      <description>&lt;P&gt;Hi - It looks like your Output and your Data A are the same; I'm not sure what your goal is or what question you're trying to answer. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm happy to help out, so I will watch for your reply.&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2017 14:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334063#M75386</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2017-02-18T14:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334066#M75387</link>
      <description>Hey Chris,&lt;BR /&gt;&lt;BR /&gt;Thanks for reaching out. Actually if you see in the output dataset , 6th and 9th transactions dont exist. this is because on the same day another transaction happened which was earlier then them.&lt;BR /&gt;&lt;BR /&gt;Eg :&lt;BR /&gt;5 trn3 13FEB2017 2.30am&lt;BR /&gt;6 trn3 13FEB2017 3.30pm&lt;BR /&gt;&lt;BR /&gt;for the combination of trn3 and date-13FEB2017, I only want to pick the one with 2.30am since that happened earlier than 3.30 pm.&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;I also added the pay variable to the output DS since I missed it earlier.</description>
      <pubDate>Sat, 18 Feb 2017 14:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334066#M75387</guid>
      <dc:creator>adityaa9z</dc:creator>
      <dc:date>2017-02-18T14:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334067#M75388</link>
      <description>&lt;P&gt;Apparently I've not had enough tea this morning - completely missed that!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think if you used something like this it should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select var_a, var_b, var_c,&amp;nbsp;
min(var_d) as FirstInstance
from work.have
group by var_a, var_b, var_c
order by var_a, var_b, var_c&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;that should give you what you need. &amp;nbsp;If it still doesn't give you what you're expecting I'll log into my SAS and create your datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2017 14:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334067#M75388</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2017-02-18T14:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334071#M75391</link>
      <description>hey Chris. That didnt work. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Sat, 18 Feb 2017 15:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334071#M75391</guid>
      <dc:creator>adityaa9z</dc:creator>
      <dc:date>2017-02-18T15:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334076#M75393</link>
      <description>&lt;P&gt;One reason why I don't like "dummy" code - you miss things that should be easy to catch!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've run this code and I think it's what you're looking for;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select min(a.id), a.act_no, a.date format=date9., min(a.time) format=time., max(b.pay)
from work.A a, work.B b
where a.id = b.id
group by a.act_no, a.date
order by a.act_no, a.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because the IDs and Pay are different for each of the act_no | date combinations, the MIN was picking up each one (because they&amp;nbsp;&lt;EM&gt;were&lt;/EM&gt; technically the minimum value for that grouping). &amp;nbsp;I've tweaked the code so it gives you:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7341iF7CE061650BAEF11/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Screen Shot 2017-02-18 at 10.27.51 AM.png" title="Screen Shot 2017-02-18 at 10.27.51 AM.png" width="297" height="221" /&gt;&lt;/P&gt;
&lt;P&gt;I realise 4 and 5 aren't in proper order; if you need the data sorted by ID, you can use PROC SQL; create table work.new_data as &amp;lt;SQL query&amp;gt;; quit; and then run PROC SORT on that table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keeping my fingers crossed this is what you're looking for!&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2017 15:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334076#M75393</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2017-02-18T15:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334082#M75396</link>
      <description>Output looks great Chris. Thanks.&lt;BR /&gt;&lt;BR /&gt;Id is the primary key. Pay can be same or different. But wondering why we have to use min and max with Id and pay. If you could help me understand it please.&lt;BR /&gt;&lt;BR /&gt;Thanks again.</description>
      <pubDate>Sat, 18 Feb 2017 15:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334082#M75396</guid>
      <dc:creator>adityaa9z</dc:creator>
      <dc:date>2017-02-18T15:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334092#M75404</link>
      <description>&lt;P&gt;In your output desired data you have selected the first row per ACT_NO and DATE, ignoring the ID .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming your data is sorted by ACT_NO DATE then select the first, by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 set data_A;
   by act_no date;
        if first.date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;that code will filter rows 6 and 9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you need filtering same rows from second table. You can do it by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    crteate table want as select a.*, b.*
    from temp as a
    left join data_B as b
    on a.id = b.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Feb 2017 16:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334092#M75404</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-18T16:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help for so proc sql step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334094#M75405</link>
      <description>&lt;P&gt;The MAX(pay) is just to select one item; you could've used MIN(pay) as well. &amp;nbsp;Play around with it and see I mean; if you need anything further, i'm around all day and will be checking in regularly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2017 16:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-for-so-proc-sql-step/m-p/334094#M75405</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2017-02-18T16:21:08Z</dc:date>
    </item>
  </channel>
</rss>

