<?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: SAS replacement for WITH AS (Oracle SQL clause)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620094#M182158</link>
    <description>&lt;P&gt;To me that looks like two different questions.&amp;nbsp; The direct answer is that SAS does no support Common Table Expressions.&amp;nbsp;&lt;A href="https://modern-sql.com/feature/with" target="_blank" rel="noopener"&gt;https://modern-sql.com/feature/with&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could either just run a separate step to create the result as a table (or view) and then reference it in your query.&amp;nbsp; Or just code it directly into your query as a subquery.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the second question is how to get the query you wrote that uses the Oracle system psuedo table DUAL to work in SAS. The easiest thing is to just use a data step to read the data as text.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data income;
  infile cards dsd truncover ;
  input Brand :$20. Income Valid_From :yymmdd. Valid_To :yymmdd. ;
  format Valid_From Valid_To yymmdd10.;
cards;
Porsche   , 40000, 2017-01-01,2999-12-31
Ferrari   , 80000, 2017-01-01,2999-12-31
Lamborghin, 50000, 2017-01-01,2019-12-31
Lamborghin, 75000, 2020-01-01,2999-12-31
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note you could trick SAS into doing something similar to DUAL by just selecting one observation from some dataset you know exists, like SASHELP.CLASS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 'Porsche' as Brand
     , 40000 as Income
     , '01JAN2017'd as Valid_From format=yymmdd10.
     , '31DEC2999'd as Valid_To format=yymmdd10.
  from sashelp.class(obs=1)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Jan 2020 21:10:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-01-26T21:10:27Z</dc:date>
    <item>
      <title>SAS replacement for WITH AS (Oracle SQL clause)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620087#M182155</link>
      <description>&lt;P&gt;Hi.&lt;BR /&gt;Is there a replacement in SAS SQL for an Oracle SQL WITH AS function?&lt;/P&gt;&lt;P&gt;Or do I have to use CASE or something like that in SAS to get the same results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How it looks like in Oracle:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;with income as (
select 'Porsche' as Brand, 40000 as Income, date'2017-01-01' as Valid_From, date'2999-12-31' as Valid_To from dual union all
select 'Ferrari' as Brand, 80000 as Income, date'2017-01-01' as Valid_From, date'2999-12-31' as Valid_To from dual union all
select 'Lamborghini' as Brand, 50000 as Income, date'2017-01-01' as Valid_From, date'2019-12-31' as Valid_To from dual union all
select 'Lamborghini' as Brand, 75000 as Income, date'2020-01-01' as Valid_From, date'2999-12-31' as Valid_To from dual union all
)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 18:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620087#M182155</guid>
      <dc:creator>MartinJurca</dc:creator>
      <dc:date>2020-01-26T18:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS replacement for WITH AS (Oracle SQL clause)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620088#M182156</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select * from (select 'Porsche' as Brand, 40000 as Income, '01Jan2017'd as Valid_From, '31Dec2999'd as Valid_To from sashelp.class(obs=1) union all
select 'Ferrari' as Brand, 80000 as Income, '01Jan2017'd as Valid_From, '31Dec2999'd as Valid_To from sashelp.class(obs=1) union all
select 'Lamborghini' as Brand, 50000 as Income, '01Jan2017'd as Valid_From, '31Dec2019'd as Valid_To from sashelp.class (obs=1) union all
select 'Lamborghini' as Brand, 75000 as Income, '01Jan2020'd as Valid_From, '31Dec2999'd as Valid_To from sashelp.class(obs=1))
; 
quit; 

data want;
infile cards dlm=',';
informat Brand $15. Valid_From Valid_To date9.;
format Valid_From Valid_To date9.;
input Brand Income Valid_From Valid_To;
cards;
Porsche, 40000, '01Jan2017', '31Dec2999'
Ferrari, 80000, '01Jan2017', '31Dec2999'
Lamborghini, 50000, '01Jan2017', '31Dec2019'
Porsche, 4000, '01Jan2020', '31Dec2999'
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like you're creating a table here with hard coded data? There's a few ways to do that in SAS. Do you need it inline, or as a subquery or can it be a separate step all together?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what you're doing overall there may be other ways, especially if this is a look up table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309006"&gt;@MartinJurca&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi.&lt;BR /&gt;Is there a replacement in SAS SQL for an Oracle SQL WITH AS function?&lt;/P&gt;
&lt;P&gt;Or do I have to use CASE or something like that in SAS to get the same results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How it looks like in Oracle:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;with income as (
select 'Porsche' as Brand, 40000 as Income, date'2017-01-01' as Valid_From, date'2999-12-31' as Valid_To from dual union all
select 'Ferrari' as Brand, 80000 as Income, date'2017-01-01' as Valid_From, date'2999-12-31' as Valid_To from dual union all
select 'Lamborghini' as Brand, 50000 as Income, date'2017-01-01' as Valid_From, date'2019-12-31' as Valid_To from dual union all
select 'Lamborghini' as Brand, 75000 as Income, date'2020-01-01' as Valid_From, date'2999-12-31' as Valid_To from dual union all
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 18:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620088#M182156</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-26T18:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS replacement for WITH AS (Oracle SQL clause)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620094#M182158</link>
      <description>&lt;P&gt;To me that looks like two different questions.&amp;nbsp; The direct answer is that SAS does no support Common Table Expressions.&amp;nbsp;&lt;A href="https://modern-sql.com/feature/with" target="_blank" rel="noopener"&gt;https://modern-sql.com/feature/with&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could either just run a separate step to create the result as a table (or view) and then reference it in your query.&amp;nbsp; Or just code it directly into your query as a subquery.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the second question is how to get the query you wrote that uses the Oracle system psuedo table DUAL to work in SAS. The easiest thing is to just use a data step to read the data as text.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data income;
  infile cards dsd truncover ;
  input Brand :$20. Income Valid_From :yymmdd. Valid_To :yymmdd. ;
  format Valid_From Valid_To yymmdd10.;
cards;
Porsche   , 40000, 2017-01-01,2999-12-31
Ferrari   , 80000, 2017-01-01,2999-12-31
Lamborghin, 50000, 2017-01-01,2019-12-31
Lamborghin, 75000, 2020-01-01,2999-12-31
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note you could trick SAS into doing something similar to DUAL by just selecting one observation from some dataset you know exists, like SASHELP.CLASS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 'Porsche' as Brand
     , 40000 as Income
     , '01JAN2017'd as Valid_From format=yymmdd10.
     , '31DEC2999'd as Valid_To format=yymmdd10.
  from sashelp.class(obs=1)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2020 21:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-replacement-for-WITH-AS-Oracle-SQL-clause/m-p/620094#M182158</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-26T21:10:27Z</dc:date>
    </item>
  </channel>
</rss>

