<?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 with restrictions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432013#M281762</link>
    <description>&lt;P&gt;1) 1 , 2, 3 etc. are not valid SAS data set names OR sql alias&lt;/P&gt;
&lt;P&gt;2) Select * doesn't rename any of the variables so you will have issues with multiple From, to and count2 clashing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest adding things one at a time until you become more familiar with nesting queries and getting the variables renamed as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this works for combining the first two sets:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table first as 
   select a.id,a.from, a.to, b.count
   from data1 as a
        left join 
        data2 as b
        on a.id=b.id
        and a.from le b.off le a.to
   ;
run;&lt;/PRE&gt;
&lt;P&gt;If that works then use the resulting First as the A set in the next block of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have to explain the rules involved with deciding that both (0,0.5) and (0.5,1)&amp;nbsp;(in the first set) matches to (0,1) but (0,1) in the first set does not match (0,1) in the third or fourth set.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2018 00:14:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-01-30T00:14:03Z</dc:date>
    <item>
      <title>How to merge data with restrictions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432008#M281761</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently working on a creating master file for further&amp;nbsp;SAS Analysis. For the most part, all 4 files are formatted to produce the master file I desire but I cannot seem to bring the files together without losing data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For starters file 1 is the base and the other 3 files will add to it. The relevant&amp;nbsp;portion of dataset 1 looks like so:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID From To&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.5&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0.5&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;0.3&amp;nbsp; &amp;nbsp; 0.7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In dataset 2 is as such:&lt;/P&gt;&lt;P&gt;IDD Off Count&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0.2&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0.7&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0.5&amp;nbsp; 8&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;0.3&amp;nbsp; 20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where IDD is the same as ID and Off in between From and To&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3/4 are similar in concept and look like so:&lt;/P&gt;&lt;P&gt;3)&lt;/P&gt;&lt;P&gt;ID FROM TO Count2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;1.65&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2.0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;0.3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.7&amp;nbsp; &amp;nbsp;1.56&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4)&lt;/P&gt;&lt;P&gt;ID FROM TO Count3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;18547&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 23506&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;0.3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.7&amp;nbsp; &amp;nbsp;6582&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where Count2 and Count are not related. I have tried the following code trying to merge 1 and 2 but the resultant (5) results in huge quantities of sections being lost (3000) observations to (700) observations.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      create table my.5 as
      select *
      from  my.1 as 1, my.2 as 2
where 1.ID = 2.IDD and 1.From&amp;lt;=2.Off and 1.To &amp;gt;= 2.Off;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Overall I wish the master file to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID From To Count Count2&amp;nbsp; &amp;nbsp;Count3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.5&amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; 1.65&amp;nbsp; &amp;nbsp; &amp;nbsp;18547&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp;0.5&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.65&amp;nbsp; &amp;nbsp; &amp;nbsp;18457&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2.0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23506&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp;0.3&amp;nbsp; &amp;nbsp; 0.7&amp;nbsp; &amp;nbsp; 20&amp;nbsp; &amp;nbsp; &amp;nbsp;1.56&amp;nbsp; &amp;nbsp; &amp;nbsp; 6582&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 01:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432008#M281761</guid>
      <dc:creator>iliyan</dc:creator>
      <dc:date>2018-01-30T01:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data with restrictions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432013#M281762</link>
      <description>&lt;P&gt;1) 1 , 2, 3 etc. are not valid SAS data set names OR sql alias&lt;/P&gt;
&lt;P&gt;2) Select * doesn't rename any of the variables so you will have issues with multiple From, to and count2 clashing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest adding things one at a time until you become more familiar with nesting queries and getting the variables renamed as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this works for combining the first two sets:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table first as 
   select a.id,a.from, a.to, b.count
   from data1 as a
        left join 
        data2 as b
        on a.id=b.id
        and a.from le b.off le a.to
   ;
run;&lt;/PRE&gt;
&lt;P&gt;If that works then use the resulting First as the A set in the next block of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have to explain the rules involved with deciding that both (0,0.5) and (0.5,1)&amp;nbsp;(in the first set) matches to (0,1) but (0,1) in the first set does not match (0,1) in the third or fourth set.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 00:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432013#M281762</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-30T00:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge data with restrictions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432016#M281763</link>
      <description>&lt;P&gt;Hello ballardw, thank you very much for your reply and interest in this matter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Yes although I call them 1,2,3 and 4 those are not the original file names, the ones I use work no problem. But to ease confusion let us refer to them as sets: A, B, C, D and E(final).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) In D I made a mistake I meant to indicate is as Count3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on merging the files one at a time and not all at once.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frist in A,C and D ID/IDD is an identifier&amp;nbsp;of a unique portion of a road. That portion is then defined by a continuous length identifier&amp;nbsp; FROM and TO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In A there are two of the same IDs because another variable(not shown) is different the requiring to split it into 2 sections.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In B only the IDD (where IDD=ID) and at some Off there is a point of interest. Thus the first line in B will only fall into the gap&amp;nbsp;between 0 and 0.5 and not the second and vice versa for the second observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apart from the naming mistake, C and D are the same sections&amp;nbsp;but the Count3 is the only observation and thus there are no splits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 01:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-merge-data-with-restrictions/m-p/432016#M281763</guid>
      <dc:creator>iliyan</dc:creator>
      <dc:date>2018-01-30T01:09:27Z</dc:date>
    </item>
  </channel>
</rss>

