<?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: simple solution sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670490#M201293</link>
    <description>&lt;P&gt;If your actual datasets are quite large, the best way (IMO) is to do this is with a hash object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result;
    if _n_=1 then do;
        declare hash b(dataset:"b");
        b.DefineKey("id");
        b.DefineData("changeY");
        b.DefineDone();
        if 0 then set b;
    end;
    
    set a;
    
    if b.find() = 0 then y = sum(y, changey);
    
    drop changeY;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 19 Jul 2020 18:27:14 GMT</pubDate>
    <dc:creator>ketpt42</dc:creator>
    <dc:date>2020-07-19T18:27:14Z</dc:date>
    <item>
      <title>simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670485#M201289</link>
      <description>&lt;P&gt;hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class="" title=""&gt;I am looking for the simplest solution to the problem presented below&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input id y; 
cards;
1 50
2 30
3 30
4 60
5 70
6 80
7 70
2 30
run;

data B;
input id changeY; 
cards;
3 300
4 472
5 111
6 2010
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;result: &amp;nbsp; if A.id = B.id then y + changeY;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;in table A&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;1 50&lt;BR /&gt;2 30&lt;BR /&gt;3 330&lt;BR /&gt;4 532&lt;BR /&gt;5 181&lt;BR /&gt;6 2810&lt;BR /&gt;7 70&lt;BR /&gt;2 30&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="text-wrap tlid-copy-target"&gt;
&lt;DIV class="result-shield-container tlid-copy-target" tabindex="0"&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class="" title=""&gt;Thank you for your help&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sun, 19 Jul 2020 18:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670485#M201289</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2020-07-19T18:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670487#M201291</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update a
set y = sum(y, (select changeY from b where a.id=b.id));
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jul 2020 18:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670487#M201291</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-07-19T18:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670488#M201292</link>
      <description>&lt;P&gt;A simple merge can do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input id y; 
cards;
1 50
2 30
3 30
4 60
5 70
6 80
7 70
2 30
;

data B;
input id changeY; 
cards;
3 300
4 472
5 111
6 2010
;

data want;
merge a b;
by id;
y = sum(y,changey);
drop changey;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2020 18:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670488#M201292</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-19T18:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670490#M201293</link>
      <description>&lt;P&gt;If your actual datasets are quite large, the best way (IMO) is to do this is with a hash object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result;
    if _n_=1 then do;
        declare hash b(dataset:"b");
        b.DefineKey("id");
        b.DefineData("changeY");
        b.DefineDone();
        if 0 then set b;
    end;
    
    set a;
    
    if b.find() = 0 then y = sum(y, changey);
    
    drop changeY;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jul 2020 18:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670490#M201293</guid>
      <dc:creator>ketpt42</dc:creator>
      <dc:date>2020-07-19T18:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670493#M201296</link>
      <description>&lt;P&gt;Even better would be to use MODIFY statement to update the existing A dataset instead of creating a new dataset.&amp;nbsp; &amp;nbsp;If A is large that will reduce a lot of I/O and disk usage.&amp;nbsp; Risk is that you will no longer have the un-modified version of A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your case is like example 3 in this version of the documentation.&amp;nbsp;&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n0g9jfr4x5hgsfn17gtma5547lt1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n0g9jfr4x5hgsfn17gtma5547lt1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
  if _n_=1 then do;
    declare hash b(dataset:"b");
    b.DefineKey("id");
    b.DefineData("changeY");
    b.DefineDone();
    if 0 then set b(keep=changeY);
  end;
  
  modify A;
  
  if 0=b.find() then do;
    y = sum(y, changey);
    replace;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;NOTE: There were 4 observations read from the data set WORK.B.
NOTE: There were 8 observations read from the data set WORK.A.
NOTE: The data set WORK.A has been updated.  There were 4 observations rewritten, 0 observations added and 0 observations deleted.


Obs    id       y

 1      1      50
 2      2      30
 3      3     330
 4      4     532
 5      5     181
 6      6    2090
 7      7      70
 8      2      30

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2020 19:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670493#M201296</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-19T19:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670591#M201341</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class="" title=""&gt;Ok thank you, unfortunately it did not work in this case:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;set y = y * (select changeY from b where a.id=b.id);&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class="" title=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 11:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670591#M201341</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2020-07-20T11:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670699#M201373</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set y = y * coalesce((select changeY from b where a.id=b.id), 1);&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 15:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670699#M201373</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-07-20T15:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: simple solution sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670955#M201452</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN title=""&gt;Thank you for solving my problem and broadening the horizon :).&lt;/SPAN&gt; &lt;SPAN title=""&gt;I have one more problem (similar in my opinion) could you help me too?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
informat datetime  datetime21.;
input datetime A B; 
format datetime  datetime21.;
cards;
   02JUN2003:21:58:00	1	8
   02JUN2003:21:58:30	2	2
   02JUN2003:21:59:00	5	3
   02JUN2003:21:59:30	8	7
   02JUN2003:22:00:00	3	2
   02JUN2003:22:00:30	4	0
   02JUN2003:22:01:00	8	0.8
   02JUN2003:22:01:30	3	1
   02JUN2003:22:02:00	2	7
   02JUN2003:22:02:30	5	3
   02JUN2003:22:03:00	2	5
   02JUN2003:22:03:30	7	8
   02JUN2003:22:04:00	9	7
   02JUN2003:22:04:30	10	2
   02JUN2003:23:05:00	6	6
   02JUN2003:23:05:30	3	7
   02JUN2003:23:06:00	7	6
run;



data B;
informat datetimeL  datetime21. datetimeR  datetime21.;
input datetimeL datetimeR move; 
format datetimeL datetimeR  datetime21.;
cards;
02JUN2003:22:00:00	02JUN2003:22:59:59	1
02JUL2003:17:00:00	02JUL2003:17:59:59	1
01AUG2003:23:00:00	01AUG2003:23:59:59	3
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN title=""&gt;&lt;SPAN class="ILfuVd"&gt;&lt;SPAN class="hgKElc"&gt;&lt;STRONG&gt;pseudocode:&lt;/STRONG&gt; if A.datetime between B.datetimeL and B.datetimeP then A.datetime = INTNX('second',A.datetime,B.move * 60)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Result;
informat datetime  datetime21.;
input datetime; 
format datetime  datetime21.;
cards;
   02JUN2003:21:58:00	1	8
   02JUN2003:21:58:30	2	2
   02JUN2003:21:59:00	5	3
   02JUN2003:21:59:30	8	7
   02JUN2003:23:00:00	3	2
   02JUN2003:23:00:30	4	0
   02JUN2003:23:01:00	8	0.8
   02JUN2003:23:01:30	3	1
   02JUN2003:23:02:00	2	7
   02JUN2003:23:02:30	5	3
   02JUN2003:23:03:00	2	5
   02JUN2003:23:03:30	7	8
   02JUN2003:23:04:00	9	7
   02JUN2003:23:04:30	10	2
   02JUN2003:23:05:00	6	6
   02JUN2003:23:05:30	3	7
   02JUN2003:23:06:00	7	6
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN title=""&gt;&lt;SPAN class="ILfuVd"&gt;&lt;SPAN class="hgKElc"&gt;&lt;STRONG&gt;&lt;SPAN class="" title=""&gt;Thank you for your help&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 12:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/simple-solution-sql/m-p/670955#M201452</guid>
      <dc:creator>makset</dc:creator>
      <dc:date>2020-07-21T12:59:16Z</dc:date>
    </item>
  </channel>
</rss>

