<?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: Combining multiple proc sql in Programming 1 and 2</title>
    <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891822#M1423</link>
    <description>&lt;P&gt;Thanks for the link. I have some experience with the first. and last. This situation is a bit more complicated as i need to use multiple BY statemants with different number of BY variables.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2023 23:14:30 GMT</pubDate>
    <dc:creator>BayzidurRahman</dc:creator>
    <dc:date>2023-08-30T23:14:30Z</dc:date>
    <item>
      <title>Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891637#M1412</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I am using the following 3 proc sql to generate 3&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table test3 as 
  select *, SUM( count ) as dur
      from test2
  group by id,gr
;
quit;

proc sql;
create table test4 as 
  select *, case 
    when dur=11 then 1
    end as stay
		    from test3
;
quit;

proc sql;
create table test5 as 
  select *, max(stay) as staykeep
	    from test4
		group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;variables from a dataset. Can you please suggest how can I do that under a single proc sql?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 05:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891637#M1412</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T05:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891644#M1413</link>
      <description>&lt;P&gt;Do you really want the remerges which will happen in the first and third SQL?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 07:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891644#M1413</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-30T07:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891645#M1414</link>
      <description>&lt;P&gt;I am not sure but need to create all those three variables.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 07:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891645#M1414</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T07:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891646#M1415</link>
      <description>&lt;P&gt;You create a &lt;U&gt;lot&lt;/U&gt; more variables, as you use the asterisk.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please supply an example for the data you start with, and what you want to get as aresult.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 07:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891646#M1415</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-30T07:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891651#M1416</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BayzidurRahman_0-1693381291256.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87295i8D76139F5F9C55AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BayzidurRahman_0-1693381291256.png" alt="BayzidurRahman_0-1693381291256.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table test3 as 
  select *, SUM( count ) as dur
      from test2
  group by id,gr
;
quit;

proc sql;
create table test4 as 
  select *, case 
    when dur&amp;gt;11 then 1
    end as stay
		    from test3
;
quit;

proc sql;
create table test5 as 
  select *, max(stay) as staykeep
	    from test4
		group by id
;
quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BayzidurRahman_0-1693381398330.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87297i0D701D9DFF9FF8C2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BayzidurRahman_0-1693381398330.png" alt="BayzidurRahman_0-1693381398330.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 07:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891651#M1416</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T07:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891655#M1417</link>
      <description>&lt;P&gt;So you already get the result you expected?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 08:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891655#M1417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-30T08:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891656#M1418</link>
      <description>&lt;P&gt;And if you're looking for code, supply data in usable form, ideally as DATA step cod with DATALINES. Pictures are not usable.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 08:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891656#M1418</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-30T08:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891671#M1419</link>
      <description>&lt;P&gt;Yes- I already got the expected results. But it took me to run 3 separate proc sql, I want to do it in one.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 11:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891671#M1419</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T11:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891804#M1420</link>
      <description>&lt;P&gt;If more concise code is your goal, you can probably create all variables with one DATA step as opposed to multiple PROC SQL queries .&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 20:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891804#M1420</guid>
      <dc:creator>SusanFarmer</dc:creator>
      <dc:date>2023-08-30T20:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891815#M1421</link>
      <description>&lt;P&gt;I am happy to do all those in one data step if possible.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 22:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891815#M1421</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T22:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891821#M1422</link>
      <description>I would use FIRST. LAST. variables with grouped data.  This URL should give you some ideas, if you haven't used them before: &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lepg/p181g1p4bw3phkn1vt5p67xvynd5.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lepg/p181g1p4bw3phkn1vt5p67xvynd5.htm&lt;/A&gt;</description>
      <pubDate>Wed, 30 Aug 2023 23:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891821#M1422</guid>
      <dc:creator>SusanFarmer</dc:creator>
      <dc:date>2023-08-30T23:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891822#M1423</link>
      <description>&lt;P&gt;Thanks for the link. I have some experience with the first. and last. This situation is a bit more complicated as i need to use multiple BY statemants with different number of BY variables.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 23:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891822#M1423</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T23:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891823#M1424</link>
      <description>It looks as if your grouping is primarily on ID with a secondary on GR.  That requires only one sort BY ID GR which produces 4 grouping variables:  FIRST.ID, LAST.ID, FIRST.GR and LAST.GR.  You can use process on the ID GR groups plus the ID only group in one step.</description>
      <pubDate>Wed, 30 Aug 2023 23:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891823#M1424</guid>
      <dc:creator>SusanFarmer</dc:creator>
      <dc:date>2023-08-30T23:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891825#M1425</link>
      <description>&lt;P&gt;It really helps us help you if you provide sample have data via a fully working data step as done in below code that should return what you're asking for.&lt;/P&gt;
&lt;P&gt;Please note that with the databases I know when using a SQL group by the select clause may only contain the grouping and aggregation variables. That you can have other variables in the select clause is a SAS SQL flavor special.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  input id gr count df date:date9.;
  format date date9.;
  datalines;
1 1 1 1 01jan2022
1 1 1 1 02jan2022
2 1 1 1 03jan2022
2 2 1 1 04jan2022
2 3 9 1 05jan2022
2 3 2 1 06jan2022
;


proc sql;
/*  create table test5 as*/
  select 
    l.*
    ,r.dur
    ,r.stay
    ,max(r.stay) as staykeep
  from
    test2 l
    inner join
    (
      select 
        id
        ,gr
        ,sum(count) as dur
        ,case
          when sum(count) = 11 then 1
          else 0
          end
          as stay 
      from test2
      group by id,gr
    ) r
    on l.id=r.id and l.gr=r.gr
    group by l.id
    order by id,gr,date
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 23:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891825#M1425</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-30T23:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891827#M1426</link>
      <description>&lt;P&gt;Hi, Sorry for the hassle. I posted a complete have data with working data step but it didn't go through. Please see it below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test2;
input obs id gr dif count;
datalines;
1 1 1 1 1 
2 1 1 1 1 
3 1 1 1 1 
4 1 1 1 1 
5 1 1 1 1 
6 1 1 1 1 
7 1 1 1 1 
8 1 1 1 1 
9 1 1 1 1 
10 1 1 1 1 
11 1 1 1 1 
12 1 1 1 1 
13 1 1 1 1 
14 1 1 1 1 
15 1 2 3 1 
16 1 2 1 1 
17 1 2 1 1 
18 1 2 1 1 
19 1 2 1 1 
20 1 2 1 1 
21 1 2 1 1 
22 1 2 1 1 
23 1 2 1 1 
24 2 1 1 1 
25 2 1 1 1 
26 2 1 1 1 
27 2 1 1 1 
28 2 1 1 1 
29 2 1 1 1 
30 2 1 1 1 
31 2 2 6 1 
32 2 2 1 1 
33 2 2 1 1 
34 2 2 1 1 
35 2 2 1 1 
36 2 2 1 1 
37 2 2 1 1 
38 2 2 1 1 
; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2023 23:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891827#M1426</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-30T23:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891828#M1427</link>
      <description>&lt;P&gt;Here the SQL that works for your sample data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/*  create table test5 as*/
  select 
    l.*
    ,r.dur
    ,r.stay
    ,max(r.stay) as staykeep
  from
    test2 l
    inner join
    (
      select 
        id
        ,gr
        ,sum(count) as dur
        ,case
          when sum(count) = 11 then 1
          else 0
          end
          as stay 
      from test2
      group by id,gr
    ) r
    on l.id=r.id and l.gr=r.gr
    group by l.id
    order by obs,id,gr
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2023 23:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891828#M1427</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-30T23:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891833#M1428</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;Thanks for the code. Would you please explain what do the 1. r. etc mean? My working dataset is quite big (~0.5 billion rows) and I found proc sql performing much slower than a data step. Is there any way to do the same in a single data step?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 00:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891833#M1428</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-31T00:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891835#M1429</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;HI,&lt;/P&gt;
&lt;P&gt;Thanks for the code. Would you please explain what do the 1. r. etc mean? My working dataset is quite big (~0.5 billion rows) and I found proc sql performing much slower than a data step. Is there any way to do the same in a single data step?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If this is about performance then you should have said so from the beginning. The SQL does internal sorting which is what impacts on performance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When it comes to performance the details matter!&lt;/P&gt;
&lt;P&gt;- Is the source data already sorted by id and gr?&lt;/P&gt;
&lt;P&gt;- Are id and gr also numerical variables in your actual data?&lt;/P&gt;
&lt;P&gt;- How much memory do you have available in your session? (proc options group=memory;run;)&lt;/P&gt;
&lt;P&gt;- Do you really need variables dur and stay or would staykeep suffice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 00:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891835#M1429</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-31T00:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891836#M1430</link>
      <description>&lt;P&gt;&lt;FONT color="#0000FF"&gt;Hi Patrick,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;Please see below. I didn't realize before that proc sql would take that long.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Is the source data already sorted by id and gr? &lt;FONT color="#0000FF"&gt;No&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;- Are id and gr also numerical variables in your actual data? &lt;FONT color="#0000FF"&gt;Yes&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;- How much memory do you have available in your session? (proc options group=memory;run;)&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;SAS (r) Proprietary Software Release 9.4 TS1M8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;Group=MEMORY&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;SORTSIZE=1073741824&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;Specifies the amount of memory that is available to the SORT procedure.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;SUMSIZE=0 Specifies a limit on the amount of memory that is available for data&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;summarization procedures when class variables are active.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;MAXMEMQUERY=0 Specifies the maximum amount of memory that is allocated for procedures.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;MEMBLKSZ=16777216 Specifies the memory block size for Windows memory-based libraries.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;MEMMAXSZ=2147483648&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;Specifies the maximum amount of memory to allocate for using memory-based&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;libraries.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;LOADMEMSIZE=0 Specifies a suggested amount of memory that is needed for executable&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;programs loaded by SAS.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;MEMSIZE=2147483648&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;Specifies the limit on the amount of virtual memory that can be used during&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;a SAS session.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;REALMEMSIZE=0 Specifies the amount of real memory SAS can expect to allocate.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Do you really need variables dur and stay or would staykeep suffice? &lt;FONT color="#0000FF"&gt;Yes, I need them&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 01:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891836#M1430</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-08-31T01:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple proc sql</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891841#M1431</link>
      <description>&lt;P&gt;Given you need to "look ahead" I wouldn't know how to get this done with a single pass through the data nor how to avoid sorting.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below what I could come up with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input obs id gr dif count;
datalines;
1 1 1 1 1 
2 1 1 1 1 
3 1 1 1 1 
4 1 1 1 1 
5 1 1 1 1 
6 1 1 1 1 
7 1 1 1 1 
8 1 1 1 1 
9 1 1 1 1 
10 1 1 1 1 
11 1 1 1 1 
15 1 2 3 1 
16 1 2 1 1 
17 1 2 1 1 
18 1 2 1 1 
19 1 2 1 1 
20 1 2 1 1 
21 1 2 1 1 
22 1 2 1 1 
23 1 2 1 1 
24 2 1 1 1 
25 2 1 1 1 
26 2 1 1 1 
27 2 1 1 1 
28 2 1 1 1 
29 2 1 1 1 
30 2 1 1 1 
31 2 2 6 1 
32 2 2 1 1 
33 2 2 1 1 
34 2 2 1 1 
35 2 2 1 1 
36 2 2 1 1 
37 2 2 1 1 
38 2 2 1 1 
;

proc sort data=have out=inter;
  by id gr;
run;

options fullstimer;
data want;
  if _n_=1 then
    do;
      length dur stay 8;
      dcl hash h1(hashexp:5);
      h1.defineKey('id','gr');
      h1.defineData('dur','stay');
      h1.defineDone();
    end;

  retain staykeep dur;
  dur=0;
  staykeep=0;

  do until(last.id);
    set inter;
    by id gr;

    dur+count;
    if last.gr then
      do;
        stay= (dur=11);
        if stay=1 then staykeep=1;
        _rc=h1.add();
        dur=0;
      end;
  end;

  last.id=0;
  do until(last.id);
    set inter;
    by id;
    _rc=h1.find();
    output;
  end;

  _rc=h1.clear();
  drop _rc;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2023 03:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Combining-multiple-proc-sql/m-p/891841#M1431</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-31T03:47:31Z</dc:date>
    </item>
  </channel>
</rss>

