<?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 How to convert multiple sort and merge into one step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173177#M33252</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to optimise the following code into one piece for sorting and merging.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data=table1;&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data= table2;&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to convert the following merge into one step as well. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want1;&lt;/P&gt;&lt;P&gt;Merge have2(in=a) have1(in=b);&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;If a;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want2;&lt;/P&gt;&lt;P&gt;Merge have3(in=a) have1(in=b);&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;If a;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have multiple sort and merge with the same by variables. Hence I wish to optimise into one step for sort and merge via macros, looping,...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any inputs to my question is highly appreciated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 15 Nov 2014 07:08:47 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2014-11-15T07:08:47Z</dc:date>
    <item>
      <title>How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173177#M33252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to optimise the following code into one piece for sorting and merging.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data=table1;&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data= table2;&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to convert the following merge into one step as well. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want1;&lt;/P&gt;&lt;P&gt;Merge have2(in=a) have1(in=b);&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;If a;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data want2;&lt;/P&gt;&lt;P&gt;Merge have3(in=a) have1(in=b);&lt;/P&gt;&lt;P&gt;By id;&lt;/P&gt;&lt;P&gt;If a;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have multiple sort and merge with the same by variables. Hence I wish to optimise into one step for sort and merge via macros, looping,...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any inputs to my question is highly appreciated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 07:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173177#M33252</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2014-11-15T07:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173178#M33253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 09:06:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173178#M33253</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2014-11-15T09:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173179#M33254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if ID value is unique, I would consider using SQL left join . or Hash Table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 09:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173179#M33254</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-15T09:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173180#M33255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Already I'm doing left join via merge in my datastep.But I wonder how to this in one proc sql to handle multiple left joins? May I ask you for the example?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How about my first question on sorting?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for your inputs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 11:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173180#M33255</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2014-11-15T11:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173181#M33256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;About merge multiple tables in a proc sql, just as simple as&lt;/P&gt;&lt;P&gt;from a left join b on ...&amp;nbsp;&amp;nbsp; left join c on ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Post some your sample data, and I believe someone is going to give you some good code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 11:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173181#M33256</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-11-15T11:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173182#M33257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We probably need more information to make a useful suggestion.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;You seem to be using DATA1 as a lookup table to merge onto the other data sets.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Not sure there is much utility into trying to combine the two merge steps into a single data step. There is not any I/O gains from that and much potential for confusion if DATA2 and DATA3 do not have the same data structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A macro solution might make writing the program easier, if it was clear what is being repeated and what varies.&lt;/P&gt;&lt;P&gt;For example perhaps you question is can I pass in one or more source dataset and have it merge on the fields from DATA1 onto each?&lt;/P&gt;&lt;P&gt;%macro test(dslist);&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(countw(&amp;amp;dslist)) ;&lt;/P&gt;&lt;P&gt;data want&amp;amp;i ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge %scan(&amp;amp;dslist,&amp;amp;i) (in=in1) data1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if in1 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test(data2 data3);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 14:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173182#M33257</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-11-15T14:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173183#M33258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the problem to solve wanting it into a single step.&lt;/P&gt;&lt;P&gt;Are there computer resource limitations to be solved?&lt;/P&gt;&lt;P&gt;Are there human brain capactity limitations?&lt;/P&gt;&lt;P&gt;Is there some code review quality question? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 15:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173183#M33258</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-11-15T15:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173184#M33259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about my question on sorting?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 16:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173184#M33259</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2014-11-15T16:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173185#M33260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My preference is when it makes sense is to define the data set at the outset as sorted by the proper variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the issue is that you are looking to perform a lookup on a variable that is NOT the natural key variable for DATA2 or DATA3 then perhaps you want to use some other method to perform the lookup than using a merge.&amp;nbsp; For example if you are just converting an coded variable to a description then using a FORMAT is the natural way to do that.&amp;nbsp; You might not need to do anything at all as you can always attach the format at the point where you need it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you code the merge using PROC SQL join instead then the PROC will decide for you if it needs to perform a sort behind the scenes.&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want1 as select * from data2 a left join data1 b on&amp;nbsp; a.id = b.id ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 16:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173185#M33260</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-11-15T16:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173186#M33261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorting is one of the best optimized processes not easily to be improved. It does often a split merge internally.&lt;/P&gt;&lt;P&gt;The typical question with that is resources usage and sizing. With short on resources to the size (big data?) the split in several steps is overcoming internal limits.&lt;/P&gt;&lt;P&gt;A RDBMS using SQL can deliver ordered data. More common coding but the cost is the resource overhead of those internal steps not being optimized, moderate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your only question seems to be on some coding practices, not turn around processing times.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;How big is your data? How fast is your machine? Is the needed additional processing time&amp;nbsp; acceptable?&lt;/P&gt;&lt;P&gt;How good are you with SQL? Are you using Eguide?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With that little information how can we give a good advice/answer?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 17:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173186#M33261</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-11-15T17:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173187#M33262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your suggestions. I've EG 5.1 and my dataset has around 50K observations. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 17:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173187#M33262</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2014-11-15T17:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert multiple sort and merge into one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173188#M33263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The bottom line.&amp;nbsp;&amp;nbsp; 50k observations is not that big (rather small these days), it could be sufficient in performance/execution without any need to tune that.&lt;/P&gt;&lt;P&gt;&amp;nbsp; Assuming those are sas datasets and you want to design a SQL query. You have a Query builder in that Eguide tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joining generating SQL is made easy that way. Result dataset getting back ordered also. There is a preview code (the Sql code) button.&lt;/P&gt;&lt;P&gt;Building a flow in EGuide is possible not really operational scheduling for a big company process but very documentative when combining that with code nodes.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your first steps above are a union and merge-join (left?)&lt;/P&gt;&lt;P&gt;Would it be possible to convert to Sql using that tool? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Nov 2014 18:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-multiple-sort-and-merge-into-one-step/m-p/173188#M33263</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-11-15T18:54:19Z</dc:date>
    </item>
  </channel>
</rss>

