<?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: Multiple proc sorts in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/585234#M75783</link>
    <description>&lt;P&gt;I came up with another method.&lt;/P&gt;&lt;P&gt;If you want to sort&amp;nbsp;&lt;EM&gt;all&amp;nbsp;&lt;/EM&gt;the datasets in a library, then it does make sense to use PROC DATASETS before using CALL EXECUTE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise, you can list the datasets in a CARDS statement in the same DATA step as the CALL EXECUTE statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   input datasets $char50. ;
   call execute 
      ("proc sort data=work."||strip(datasets)||
       "(keep=cum_freq cum_date rename=(cum_freq="||strip(datasets)||"))"||
       "out="||strip(datasets)||";"||
       "by ByVariable; run;");
   cards;
      dataset1
      dataset2
      dataset3
   ;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Aug 2019 15:05:42 GMT</pubDate>
    <dc:creator>mmayorga</dc:creator>
    <dc:date>2019-08-30T15:05:42Z</dc:date>
    <item>
      <title>Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36589#M9226</link>
      <description>I would like to sort more than one dataset with a common by variable in one proc sort.&lt;BR /&gt;
&lt;BR /&gt;
is this possible?&lt;BR /&gt;
if so, please assist with syntax.</description>
      <pubDate>Thu, 17 Jun 2010 06:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36589#M9226</guid>
      <dc:creator>Jackie_Stanbank</dc:creator>
      <dc:date>2010-06-17T06:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36590#M9227</link>
      <description>No.&lt;BR /&gt;
If you want to minimize coding you cold wrap your sort into a macro.&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 17 Jun 2010 08:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36590#M9227</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-06-17T08:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36591#M9228</link>
      <description>Consider declaring a SAS macro variable (or a SAS79-style macro statement), such as:&lt;BR /&gt;
&lt;BR /&gt;
%LET BY_VARS = A B C; - macro variable declared &lt;BR /&gt;
BY &amp;amp;BY_VARS;  - now reference the macro variable&lt;BR /&gt;
&lt;BR /&gt;
..or..&lt;BR /&gt;
&lt;BR /&gt;
MACRO _BYVARS A B C %  - macro statement declared&lt;BR /&gt;
BY _BYVARS; - now reference the macro statement&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 17 Jun 2010 12:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36591#M9228</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-06-17T12:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36592#M9229</link>
      <description>try this:&lt;BR /&gt;
&lt;BR /&gt;
%macro st (ds);&lt;BR /&gt;
proc sort data = &amp;amp;ds;&lt;BR /&gt;
by var1 var2 var3;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
%st(dataset1);&lt;BR /&gt;
%st(dataset2);&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
GL</description>
      <pubDate>Thu, 17 Jun 2010 14:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36592#M9229</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-17T14:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36593#M9230</link>
      <description>If you have to sort all these data sets in order to merge them using a common key then consider using PROC SQL instead of a data step as there data sets don't need to be pre-sorted for joining them.</description>
      <pubDate>Fri, 18 Jun 2010 12:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/36593#M9230</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-06-18T12:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/576636#M75485</link>
      <description>&lt;P&gt;If the ultimate goal is to merge multiple datasets, then you can do it using PROC SQL.&lt;/P&gt;&lt;P&gt;The code below is an excerpt from "PROC SQL: Tips and Translations for Data Step Users" by Susan P Marcella &amp;amp; Gail Jorgensen, which you can find here:&amp;nbsp;&lt;A href="https://www.lexjansen.com/nesug/nesug10/hw/hw05.pdf" target="_blank" rel="noopener"&gt;https://www.lexjansen.com/nesug/nesug10/hw/hw05.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Instead of this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=L.drinkers; by id; run;
proc sort data=L.smokers; by id; run;
data L.LJSmokeDrinkdata;
merge L.smokers(in=smoke) L.drinkers(in=drink);
by id;
if smoke;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Use this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table L.LJSmokeDrinkSQL as
select s.*, d.*
from L.smokers as s join L.drinkers as d
on s.id=d.id;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Alternatively, you can use PROC DATASETS and the CALL EXECUTE statement within a DATA step to sort datasets.&lt;/P&gt;&lt;P&gt;In the code below, I first create the dataset myMembers, which contains the variable NAME that gives me the names of all Datasets (memtype=data) on the WORK library.&lt;/P&gt;&lt;P&gt;Then, CALL EXECUTE allows me to run the same code on all datasets that have the letter 't' in their name (specified by the WHERE statement).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output Members=myMembers;
proc datasets lib=work memtype=data; run;
ods output close;

data _null_; set myMembers; 
	call execute ('proc sort data=work.'||strip(Name)||'; by Patient_ID; run;');
	where find(name,'t','i');
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I usually reserve CALL EXECUTE for instances where I have several lines of code to do on at least 5 datasets, or simple code on more than 10 datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps! Good luck!&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 22 Oct 2019 15:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/576636#M75485</guid>
      <dc:creator>mmayorga</dc:creator>
      <dc:date>2019-10-22T15:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple proc sorts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/585234#M75783</link>
      <description>&lt;P&gt;I came up with another method.&lt;/P&gt;&lt;P&gt;If you want to sort&amp;nbsp;&lt;EM&gt;all&amp;nbsp;&lt;/EM&gt;the datasets in a library, then it does make sense to use PROC DATASETS before using CALL EXECUTE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise, you can list the datasets in a CARDS statement in the same DATA step as the CALL EXECUTE statement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   input datasets $char50. ;
   call execute 
      ("proc sort data=work."||strip(datasets)||
       "(keep=cum_freq cum_date rename=(cum_freq="||strip(datasets)||"))"||
       "out="||strip(datasets)||";"||
       "by ByVariable; run;");
   cards;
      dataset1
      dataset2
      dataset3
   ;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Aug 2019 15:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-proc-sorts/m-p/585234#M75783</guid>
      <dc:creator>mmayorga</dc:creator>
      <dc:date>2019-08-30T15:05:42Z</dc:date>
    </item>
  </channel>
</rss>

