<?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 merging two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553473#M153914</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Have a project for school and we are beginners in SAS programming.&amp;nbsp; We are having a bit of trouble merging an environmental dataset (daily data for 10 years) with a birth cohort dataset (n = ~350,000). Essentially, we want to tell SAS to start in the birth dataset (in which we have a subject ID, county of residence and&amp;nbsp; pregnancy date range for each individual subject (FirstDayPreg LastDayPreg), then go to the air quality data set and count the number of exceedances (ExpLevel coded as 0 or 1.&amp;nbsp; 1 if exceeds daily threshold for various air quality metrics) within that pregnancy date range, and then output the number of exceedances by subject ID. We have tried to accomplish this with PROC SQL and nested DO loops, but can't quite seem to figure it out. An image of environmental data set and birth cohort data are attached.&amp;nbsp; We would really appreciate any assistance you can provide us.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Birth cohort data" style="width: 543px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28955iBC24B49D97201BAF/image-size/large?v=v2&amp;amp;px=999" role="button" title="BirthCohort.JPG" alt="Birth cohort data" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Birth cohort data&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Environmental data" style="width: 482px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28956i6C1ECA16B72004A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="EnvironData.JPG" alt="Environmental data" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Environmental data&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Apr 2019 23:54:31 GMT</pubDate>
    <dc:creator>beckwaller</dc:creator>
    <dc:date>2019-04-23T23:54:31Z</dc:date>
    <item>
      <title>merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553473#M153914</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Have a project for school and we are beginners in SAS programming.&amp;nbsp; We are having a bit of trouble merging an environmental dataset (daily data for 10 years) with a birth cohort dataset (n = ~350,000). Essentially, we want to tell SAS to start in the birth dataset (in which we have a subject ID, county of residence and&amp;nbsp; pregnancy date range for each individual subject (FirstDayPreg LastDayPreg), then go to the air quality data set and count the number of exceedances (ExpLevel coded as 0 or 1.&amp;nbsp; 1 if exceeds daily threshold for various air quality metrics) within that pregnancy date range, and then output the number of exceedances by subject ID. We have tried to accomplish this with PROC SQL and nested DO loops, but can't quite seem to figure it out. An image of environmental data set and birth cohort data are attached.&amp;nbsp; We would really appreciate any assistance you can provide us.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Birth cohort data" style="width: 543px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28955iBC24B49D97201BAF/image-size/large?v=v2&amp;amp;px=999" role="button" title="BirthCohort.JPG" alt="Birth cohort data" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Birth cohort data&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Environmental data" style="width: 482px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28956i6C1ECA16B72004A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="EnvironData.JPG" alt="Environmental data" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Environmental data&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 23:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553473#M153914</guid>
      <dc:creator>beckwaller</dc:creator>
      <dc:date>2019-04-23T23:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553481#M153917</link>
      <description>&lt;P&gt;Assuming that Date, firstPregDay and lastPregDay are SAS dates and that the air quality dataset is complete for the pregnancy periods, the following will do the counts:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table expCounts as
select
    a.id,
    a.county,
    sum(b.ExpLevel) as expCount
from 
    birth as a inner join
    air as b on 
        a.county=b.county and 
        b.date between a.firstPregDay and a.lastPregDay
group by a.id, a.county;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT Added county to group by clause.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553481#M153917</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-24T01:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553490#M153923</link>
      <description>&lt;P&gt;Thanks!&amp;nbsp; I gave the code a shot, but I just get the following.&amp;nbsp; This was part of our issue.&amp;nbsp; We just want one value for each subject ID.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="trial1JPG.JPG" style="width: 551px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28960i0CC478EAF8EF212E/image-size/large?v=v2&amp;amp;px=999" role="button" title="trial1JPG.JPG" alt="trial1JPG.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553490#M153923</guid>
      <dc:creator>beckwaller</dc:creator>
      <dc:date>2019-04-24T01:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553492#M153925</link>
      <description>&lt;P&gt;I think it was because we had to create firstpregday and lastpregday from existing variables and they are not SAS dates&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553492#M153925</guid>
      <dc:creator>beckwaller</dc:creator>
      <dc:date>2019-04-24T01:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553493#M153926</link>
      <description>&lt;P&gt;Please try the new version above.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553493#M153926</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-24T01:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553495#M153927</link>
      <description>&lt;P&gt;That worked! Thank you.&amp;nbsp; We haven't made it to Proc sql yet in class.&amp;nbsp; I really appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 01:58:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553495#M153927</guid>
      <dc:creator>beckwaller</dc:creator>
      <dc:date>2019-04-24T01:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: merging two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553547#M153949</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/245246"&gt;@beckwaller&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to see that PGStats's solution worked for you. Then i&lt;SPAN&gt;t would help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: see &lt;A href="https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-between-two-hex-data/m-p/552509#M153587" target="_blank" rel="noopener"&gt;instructions here&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 08:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-two-datasets/m-p/553547#M153949</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-04-24T08:01:22Z</dc:date>
    </item>
  </channel>
</rss>

