<?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: How to merge data by date rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577174#M163530</link>
    <description>&lt;P&gt;You didn't show the structure for your temperature dataset.&amp;nbsp; But assuming that it has DATE and WALL in addition to TEMPERATURE then the you should be able to use SQL to join on WALL and when the date for temperature falls within the interval you wanted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date :mmddyy. wall gas_concentration;
  format date yymmdd10.;
cards;
05/19/2014 11 220
05/19/2014 12 213
05/19/2014 13 180
05/19/2014 15 451
;

data temp;
  input date :mmddyy. wall temperature ;
  format date yymmdd10.;
cards;
01/18/2014 11  30
01/19/2014 11  32
01/20/2014 11  33
01/21/2014 11  30
05/19/2014 11  31
05/20/2014 11  32
;

proc sql ;
 create table want as 
   select a.date,a.wall,b.gas_concentration,a.temperature 
   from temp a
   inner join have b
   on a.wall = b.wall
    and a.date between intnx('month',b.date,-4,'same') and b.date
   order by 1,2
 ;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs          date    wall    gas_concentration    temperature

 1     2014-01-19     11            220                32
 2     2014-01-20     11            220                33
 3     2014-01-21     11            220                30
 4     2014-05-19     11            220                31&lt;/PRE&gt;</description>
    <pubDate>Sat, 27 Jul 2019 16:31:26 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-07-27T16:31:26Z</dc:date>
    <item>
      <title>How to merge data by date rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577173#M163529</link>
      <description>&lt;P&gt;HI there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data, indicating one gas fixed in a surface:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input data wall gas_concentration;&lt;/P&gt;
&lt;P&gt;cards;&lt;/P&gt;
&lt;P&gt;05/19/2014 11 220&lt;/P&gt;
&lt;P&gt;05/19/2014 12 213&lt;/P&gt;
&lt;P&gt;05/19/2014 13 180&lt;/P&gt;
&lt;P&gt;05/19/2014 15 451&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the same time, i have environmental data associated to this fixation, from 4 months before sample collection, ans now i need toputgas concentration collected to each day from 4 months ago, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wal&amp;nbsp; concentration&amp;nbsp;&amp;nbsp; temperature&lt;/P&gt;
&lt;P&gt;01/19/2014 11 220 32&lt;/P&gt;
&lt;P&gt;01/20/2014 11 220 33&lt;/P&gt;
&lt;P&gt;01/21/2014 11 220 30&lt;/P&gt;
&lt;P&gt;01/22/2014 11 220 28&lt;/P&gt;
&lt;P&gt;01/23/2014 11 220 33&lt;/P&gt;
&lt;P&gt;01/24/2014 11 220 32&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;05/19/2014 11 220 25&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the same for other walls where the samples were collected in the corresponding dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jul 2019 16:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577173#M163529</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2019-07-27T16:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data by date rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577174#M163530</link>
      <description>&lt;P&gt;You didn't show the structure for your temperature dataset.&amp;nbsp; But assuming that it has DATE and WALL in addition to TEMPERATURE then the you should be able to use SQL to join on WALL and when the date for temperature falls within the interval you wanted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date :mmddyy. wall gas_concentration;
  format date yymmdd10.;
cards;
05/19/2014 11 220
05/19/2014 12 213
05/19/2014 13 180
05/19/2014 15 451
;

data temp;
  input date :mmddyy. wall temperature ;
  format date yymmdd10.;
cards;
01/18/2014 11  30
01/19/2014 11  32
01/20/2014 11  33
01/21/2014 11  30
05/19/2014 11  31
05/20/2014 11  32
;

proc sql ;
 create table want as 
   select a.date,a.wall,b.gas_concentration,a.temperature 
   from temp a
   inner join have b
   on a.wall = b.wall
    and a.date between intnx('month',b.date,-4,'same') and b.date
   order by 1,2
 ;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs          date    wall    gas_concentration    temperature

 1     2014-01-19     11            220                32
 2     2014-01-20     11            220                33
 3     2014-01-21     11            220                30
 4     2014-05-19     11            220                31&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 16:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577174#M163530</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-27T16:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data by date rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577185#M163535</link>
      <description>&lt;P&gt;Nice program my friend&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how could it be having this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; :mmddyy&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; wall gas_concentration&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;
05/19/2014 11 220
05/19/2014 12 213
05/19/2014 13 180
05/19/2014 15 451
&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; temp&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; :mmddyy&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; temperature &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; yymmdd10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;
01/18/2014  30
01/19/2014  32
01/20/2014  33
01/21/2014  30
05/19/2014  31
05/20/2014  32
&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;BR /&gt;With&amp;nbsp;no&amp;nbsp;wall&amp;nbsp;information&amp;nbsp;in&amp;nbsp;data&amp;nbsp;temp&lt;BR /&gt;&lt;BR /&gt;Thanks&amp;nbsp;in&amp;nbsp;advance&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 18:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577185#M163535</guid>
      <dc:creator>jonatan_velarde</dc:creator>
      <dc:date>2019-07-27T18:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data by date rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577242#M163554</link>
      <description>&lt;P&gt;Just remove the condition that requires the WALL values to match from the ON clause.&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jul 2019 16:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-by-date-rows/m-p/577242#M163554</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-28T16:49:41Z</dc:date>
    </item>
  </channel>
</rss>

