<?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: Combing data from 2 different files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683522#M207051</link>
    <description>i looked for some place to edit the title or contents and could not see anything.&lt;BR /&gt;&lt;BR /&gt;can you point me to it?&lt;BR /&gt;&lt;BR /&gt;thanks!</description>
    <pubDate>Sun, 13 Sep 2020 17:34:34 GMT</pubDate>
    <dc:creator>gwa000</dc:creator>
    <dc:date>2020-09-13T17:34:34Z</dc:date>
    <item>
      <title>Combining data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683479#M207028</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;started playing around with SAS University and need help on best way to perform a task.&amp;nbsp; have not used SAS for over 30 years so i'm a little rusty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have two files which i can import into a SAS data set.&amp;nbsp; one is the electric bill information that contains an end date (i.e. meter read), number of days in billing cycle, kilowatt hours used, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the other file contains weather information (daily) such as temperature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to add the average temperature for each billing cycle month into the electric bill data set.&lt;/P&gt;&lt;P&gt;if the electric bill information was by month (1st of month to end of month) it would be trivial.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however, the electric bill goes from, say the 16th of the previous month to the 15th of the current month (i.e. the end date) for each billing cycle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i want to do is capture the monthly data from the weather data set from the 16th of the previous month to the 15th of the billing month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what's the best way to process this?&amp;nbsp; if i have a set statement for the electric bill can i go into a loop from the 16th of the month to the 15th of the next month and in this loop have another set statement to read the weather data set for those dates that encompass the billing cycle?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you process two data sets that contain different types of data in a data step?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is the way i describe the best solution or is there an easier way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 21:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683479#M207028</guid>
      <dc:creator>gwa000</dc:creator>
      <dc:date>2020-09-14T21:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683480#M207029</link>
      <description>Subject should be "Combining data from 2 different files".</description>
      <pubDate>Sat, 12 Sep 2020 23:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683480#M207029</guid>
      <dc:creator>gwa000</dc:creator>
      <dc:date>2020-09-12T23:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683482#M207031</link>
      <description>&lt;P&gt;You can edit your post and fix the title.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 02:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683482#M207031</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-13T02:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683483#M207032</link>
      <description>&lt;P&gt;A simple way to do this would be to&lt;/P&gt;
&lt;P&gt;1. Calculate the average temperature for the previous 30 days for every calendar day&lt;/P&gt;
&lt;P&gt;2. Merge that table of averages to the original table, using the end-of-cycle date as a key&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 02:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683483#M207032</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-13T02:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683494#M207039</link>
      <description>&lt;P&gt;Considering the reality that each premise could have a different reading date and reading interval you should aggregate the temperature data over the actual reading interval.&amp;nbsp; SQL is effective for joining two different data sets when there are different levels of granularity and one has to be aggregated.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data premises;
  call streaminit(123);
  do premise_id = 1 to 100;
    read_date = '01jan2018'd + rand('integer',27);
    days = .;
    do until (read_date &amp;gt; '01aug2020'd);
      kw = 250 + rand('integer',125);
      output;
      days = intnx('month',read_date,1,'SAME') - read_date;
      read_date + days;
    end;
  end;
  format read_date yymmdd10.;
run;

data temperatures(keep=date temp);
  call streaminit(123);
  do date = '01oct2017'd to '01aug2020'd;
    day = mod(juldate(date),1000);
    temp = 50 + floor(60 * sin((day/365-.24)*6.28));
    output;
  end;
  format date yymmdd10.;
  label temp='Average temp (deg F)';
run;

proc sql;
  create table want as 
  select 
    premise_id
  , read_date
  , days
  , kw
  , mean(T.temp) format=6.1 label='Mean average daily temperature in reading period'
  from
    premises P
  left join 
    temperatures T
  on 
    T.date between P.read_date and P.read_date - P.days + 1
    and P.days is not null
  group by 
    premise_id
  , read_date
  , days
  , kw
  order by
    premise_id, read_date
  ;
quit;&lt;/PRE&gt;
&lt;P&gt;Also, a more realistic situation would deal with separate temperature measure for differing premise geographic zones.&amp;nbsp; Energy delivery systems also perform estimates based on 'degree days', which would be a 'dynamic interval' in certain analyses.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 07:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683494#M207039</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-13T07:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683522#M207051</link>
      <description>i looked for some place to edit the title or contents and could not see anything.&lt;BR /&gt;&lt;BR /&gt;can you point me to it?&lt;BR /&gt;&lt;BR /&gt;thanks!</description>
      <pubDate>Sun, 13 Sep 2020 17:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683522#M207051</guid>
      <dc:creator>gwa000</dc:creator>
      <dc:date>2020-09-13T17:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683524#M207052</link>
      <description>the only problem with this approach is months do not always contain 30 days. a quick look at my data shows that the billing cycle can be anywhere from 27 days to 35 days. your approach would give a reasonable approximation but if i'm going to try to do this analysis i'd like it to be accurate (yeah, i'm sort of **bleep** about things like this!!).</description>
      <pubDate>Sun, 13 Sep 2020 17:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683524#M207052</guid>
      <dc:creator>gwa000</dc:creator>
      <dc:date>2020-09-13T17:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683527#M207053</link>
      <description>&lt;P&gt;richard,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but... i'm kind of lost on the your generation of the electric bill information.&amp;nbsp; not sure what the premise_id variable is for but what i see are dates going from 2018-01-17 to 2020-07-17 for premise_id of 1 and each observation is for the 17th.&amp;nbsp; then you do something similar for premise_id of 2 where the dates go from 2018-01-13 to 2020-07-13 and each observation is for the 13th.&lt;/P&gt;&lt;P&gt;so i'm not sure why you loop for 100 iterations to create the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you explain why there are 3100 observations when i would think you have one observation per billing cycle?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i also see multiple observations for a given read date.&amp;nbsp; so i'm sort of confused on why the data is generated as such.&lt;/P&gt;&lt;P&gt;i was also not expecting for anyone to create code to this extent.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the way my data looks is as follows:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;Read Date Days Usage&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;--------- ---- -----&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;1/15/2020&amp;nbsp; 30 &amp;nbsp; 2558&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;2/18/2020&amp;nbsp; 34 &amp;nbsp; 3305&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3/16/2020&amp;nbsp; 27 &amp;nbsp; 2029&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;4/15/2020&amp;nbsp; 30 &amp;nbsp; 1563&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;5/15/2020&amp;nbsp; 30 &amp;nbsp; 1515&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;6/15/2020&amp;nbsp; 31 &amp;nbsp; 1244&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;7/15/2020&amp;nbsp; 30&amp;nbsp;&amp;nbsp; 1468&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="3"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;given that this is how my data is, would it still be appropriate to use SQL for massaging the temperature data into the billing period.&amp;nbsp; for example, i would want to average the daily temperature from 6/16/2020 to 7/15/2020 from the temperature data set and merge that into the observation for the read date of 7/15/2020.&lt;/FONT&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="3"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;your right as far as the "degree days".&amp;nbsp; i wish that this was provided on the bill.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;thanks!!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 18:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683527#M207053</guid>
      <dc:creator>gwa000</dc:creator>
      <dc:date>2020-09-13T18:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683543#M207061</link>
      <description>&lt;P&gt;PREMISE_ID identifies a single meter for billing.&amp;nbsp; So, the data is for 100 'houses'.&amp;nbsp; I also generated 31 monthly readings (READ_DATE) for each premise with random KW usage.&amp;nbsp; (I chose the simulated data first and last read_date arbitrarily, turns out it was 31 months worth).&amp;nbsp; So 100 houses * 31 months is 3100 readings - one reading per billing cycle per premise.&amp;nbsp; The first READ_DATE for each PREMISE is a random day of JAN 2018, to simulate different premises having different 'billing' or 'reading' cycles, which would then force each temperature averaging wanted to be based on the reading cycle (handled by the SQL join criteria "on T.date between P.read_date and P.read_date - P.days + 1".&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 00:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683543#M207061</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-14T00:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683554#M207064</link>
      <description>&lt;P&gt;See here&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChrisNZ_0-1600055592605.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49313iF247490289FFB2FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChrisNZ_0-1600055592605.png" alt="ChrisNZ_0-1600055592605.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 03:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683554#M207064</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-14T03:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data from 2 different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683556#M207066</link>
      <description>&lt;P&gt;Just calculate several averages then, and merge to fetch the appropriate one.&lt;/P&gt;
&lt;P&gt;This could be your merge table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEMPERATURES;
  do DATE='01jan2000'd to '30aug2020'd ;
    VALUE=ranuni(1);
    output;
  end;
run;

data INTERVALS;
  do INTERVAL=25 to 35;
    output; 
  end;
run;

proc sql;
  create table AVG_TEMP as
  select a.DATE
       , a.VALUE
       , INTERVAL
       , mean(b.VALUE)    as AVG_VALUE
       , count(b.VALUE)   as NB_VALUES
  from TEMPERATURES    a 
         cross join
       INTERVALS       i
         full join  
       TEMPERATURES    b
         on a.DATE - b.DATE between 0 and INTERVAL
  group by 1,2,3
  order by 1,2,3 ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 04:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-data-from-2-different-files/m-p/683556#M207066</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-14T04:32:55Z</dc:date>
    </item>
  </channel>
</rss>

