<?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: DO Loop with OUTPUT in SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559237#M156137</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173881"&gt;@Junyong&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The undocumented MONOTONIC function might come in handy, but I wouldn't recommend this because it's undocumented and you need a sufficiently large arbitrary dataset (here, e.g., SASHELP.CARS with its 428&amp;gt;=240 observations) as a basis.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table monthend as
select intnx('month', &amp;amp;start, i, 'e') as date format=yymmddn8.
from (select monotonic()-1 as i from sashelp.cars
      where calculated i&amp;lt;=intck('month', &amp;amp;start, &amp;amp;finish))
order by date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is much better to use a DATA step for this task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Just for fun: If you don't want to rely on an existing dataset such as SASHELP.CARS, you can create one yourself, let's call it BASE (although, again, PROC SQL is not the ideal tool for this).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table seed (x num);
insert into seed
set x=0
set x=1;

select 'seed'||repeat(',seed',int(log2(max(intck('month',&amp;amp;start,&amp;amp;finish),1))-1)) into :ds
from seed;

create table base as
select ' ' from &amp;amp;ds;

create table monthend as
select intnx('month', &amp;amp;start, i, 'e') as date format=yymmddn8.
from (select monotonic()-1 as i from base
      where calculated i&amp;lt;=intck('month', &amp;amp;start, &amp;amp;finish))
order by date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 10:45:50 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-05-16T10:45:50Z</dc:date>
    <item>
      <title>DO Loop with OUTPUT in SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559189#M156118</link>
      <description>&lt;P&gt;Currently I am studying how to use SQL. Suppose generate month-end observations using DO and OUTPUT in DATA as follows.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start="1jan2000"d;
%let finish="31dec2019"d;
data monthend;
format date yymmddn8.;
do date=&amp;amp;start. to &amp;amp;finish.;
if date=intnx("month",date,0,"e") then output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can I do the similar thing in SQL too?&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 22:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559189#M156118</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2019-05-15T22:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop with OUTPUT in SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559192#M156119</link>
      <description>&lt;P&gt;I'm sure someone can come up with a way to do this in SQL, but it is the wrong tool for the job. Your DATA step is the proper tool to do this kind of looping.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 23:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559192#M156119</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-15T23:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop with OUTPUT in SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559196#M156120</link>
      <description>Hi:&lt;BR /&gt;  You can't use SQL for looping like this. SQL does not have the concept of iterative DO loops. The DATA step is the correct tool for the job. &lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Thu, 16 May 2019 00:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559196#M156120</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-05-16T00:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop with OUTPUT in SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559206#M156127</link>
      <description>&lt;P&gt;I don't think you can generate such a series with SAS/SQL without a macro front end. Should be done efficiently with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start="1jan2000"d;
%let finish="31dec2019"d;
data monthend;
format date yymmddn8.;
date = intnx("month", &amp;amp;start., 0, "e");
do while(date &amp;lt;= &amp;amp;finish.);
    output;
    date = intnx("month", date, 1, "e");
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 May 2019 02:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559206#M156127</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-05-16T02:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop with OUTPUT in SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559210#M156128</link>
      <description>&lt;P&gt;Possible with Oracle SQL but not SAS SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 03:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559210#M156128</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-16T03:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop with OUTPUT in SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559237#M156137</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173881"&gt;@Junyong&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The undocumented MONOTONIC function might come in handy, but I wouldn't recommend this because it's undocumented and you need a sufficiently large arbitrary dataset (here, e.g., SASHELP.CARS with its 428&amp;gt;=240 observations) as a basis.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table monthend as
select intnx('month', &amp;amp;start, i, 'e') as date format=yymmddn8.
from (select monotonic()-1 as i from sashelp.cars
      where calculated i&amp;lt;=intck('month', &amp;amp;start, &amp;amp;finish))
order by date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is much better to use a DATA step for this task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Just for fun: If you don't want to rely on an existing dataset such as SASHELP.CARS, you can create one yourself, let's call it BASE (although, again, PROC SQL is not the ideal tool for this).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table seed (x num);
insert into seed
set x=0
set x=1;

select 'seed'||repeat(',seed',int(log2(max(intck('month',&amp;amp;start,&amp;amp;finish),1))-1)) into :ds
from seed;

create table base as
select ' ' from &amp;amp;ds;

create table monthend as
select intnx('month', &amp;amp;start, i, 'e') as date format=yymmddn8.
from (select monotonic()-1 as i from base
      where calculated i&amp;lt;=intck('month', &amp;amp;start, &amp;amp;finish))
order by date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 10:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-Loop-with-OUTPUT-in-SQL/m-p/559237#M156137</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-16T10:45:50Z</dc:date>
    </item>
  </channel>
</rss>

