<?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 to SQL in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302046#M20501</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86499"&gt;@yudhishtirb&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# means temperory tables just like datasets we are creating in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it dont have any impact of changing date to datetime.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just need explanation for below line&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What actually this line does ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If dtfileclosed is not missing (. is a missing numerical value in SAS) then set dtQueryResolvedDate to the value of dtfileclosed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I managed to get your data step results with the following code in SQL also:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dtfileclosed :datetime23.3 dtqueryresolveddate :datetime23.3;
format dtfileclosed datetime23.3 dtqueryresolveddate datetime23.3;
cards;
. .
03oct2016:00:00:00.000 .
. 03oct2016:00:00:00.000
02oct2016:00:00:00.000 03oct2016:00:00:00.000
;
run;

data want1;
set have;
if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed;
if dtQueryResolvedDate = . then dtQueryResolvedDate="01JAN1900:00:00:00.000"dt;
if dtQueryResolvedDate = "01JAN1900:00:00:00.000"dt then resolved = 0; else resolved=1;
run;

proc print noobs;
run;

proc sql;
create table want2 as
select
  case
    when dtfileclosed ne . then dtfileclosed
    when dtQueryResolvedDate = . and dtfileclosed = . then "01JAN1900:00:00:00.000"dt
    else dtQueryResolvedDate
  end as dtQueryResolvedDate format=datetime23.3,
  case
    when calculated dtQueryResolvedDate ne "01JAN1900:00:00:00.000"dt then 1
    else 0
  end as resolved
from have;
quit;

proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;PRE&gt;          dtfileclosed        dtqueryresolveddate    resolved

                     .     01JAN1900:00:00:00.000        0   
03OCT2016:00:00:00.000     03OCT2016:00:00:00.000        1   
                     .     03OCT2016:00:00:00.000        1   
02OCT2016:00:00:00.000     02OCT2016:00:00:00.000        1   
                                                             

                dtQueryResolvedDate    resolved

             01JAN1900:00:00:00.000        0   
             03OCT2016:00:00:00.000        1   
             03OCT2016:00:00:00.000        1   
             02OCT2016:00:00:00.000        1   
&lt;/PRE&gt;
&lt;P&gt;Note that if you want to base a CASE statement on the result of another CASE, use "calculated" to distinguish the newly created value from the original database column.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Oct 2016 13:45:05 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-10-03T13:45:05Z</dc:date>
    <item>
      <title>SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302028#M20495</link>
      <description>&lt;P&gt;Hello Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to conver below statement is SQL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed;&lt;BR /&gt;if dtQueryResolvedDate = . then dtQueryResolvedDate="01JAN1900:00:00:00.000"dt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL :&lt;/P&gt;&lt;P&gt;CASE&lt;BR /&gt;WHEN #Master_2.dtFileClosed IS NOT NULL THEN #Master_2.dtFileClosed&lt;BR /&gt;WHEN dtQueryResolvedDate IS NULL THEN '01-01-1900'&lt;BR /&gt;ELSE dtQueryResolvedDate&lt;BR /&gt;END AS dtQueryResolvedDate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS :&lt;/P&gt;&lt;P&gt;if dtQueryResolvedDate = "01JAN1900:00:00:00.000"dt then resolved = 0; else resolved=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL :&lt;/P&gt;&lt;P&gt;CASE WHEN #master_query_4.dtQueryResolvedDate = '01-01-1900' THEN 0 ELSE 1 END AS resolved&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it is not showing correct output ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks In Advance&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 12:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302028#M20495</guid>
      <dc:creator>yudhishtirb</dc:creator>
      <dc:date>2016-10-03T12:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302031#M20496</link>
      <description>&lt;P&gt;SAS date literal are specified as ddMONyyyy ie '01Jan1990'd not '01-01-1900'&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 13:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302031#M20496</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-03T13:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302032#M20497</link>
      <description>&lt;P&gt;Actually, it's date time not a date so use the original value specified. Not sure why you changed it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you switiching to SAS SQL or a different type?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 13:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302032#M20497</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-03T13:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302035#M20498</link>
      <description>&lt;P&gt;I guess the OP is switching to a non-SAS SQL, as the table names are not SAS-compliant (start with a #).&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 13:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302035#M20498</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-03T13:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302042#M20499</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# means temperory tables just like datasets we are creating in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also it dont have any impact of changing date to datetime.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need explanation for below line&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What actually this line does ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 13:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302042#M20499</guid>
      <dc:creator>yudhishtirb</dc:creator>
      <dc:date>2016-10-03T13:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302044#M20500</link>
      <description>&lt;P&gt;&lt;SPAN&gt;if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Assuming dtfileclose is a SAS date variable, then it is a numeric value - number of days since a certain timepoint. &amp;nbsp;If it contains no data, then as per numerics it is ., which is the missing numeric data in SAS. &amp;nbsp;So the statement is saying, if dtfileclosed has some data, then set the variable dtqueryresolveddate to be the value in dtfileclosed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Case equivalent:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;case when dtfileclosed is not null then dtfileclosed&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else . end as dtqueryresolveddate&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What is happening, as previous posters have mentioned is that you are mixing up SQL datatypes and SAS datatypes. &amp;nbsp;Why do you need SQL for this? &amp;nbsp;Post exact full code, showing which system you are using, is this pass through, is it within SAS, is it nothing to do with SAS at all?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 13:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302044#M20500</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-03T13:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302046#M20501</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86499"&gt;@yudhishtirb&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;# means temperory tables just like datasets we are creating in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it dont have any impact of changing date to datetime.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just need explanation for below line&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What actually this line does ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If dtfileclosed is not missing (. is a missing numerical value in SAS) then set dtQueryResolvedDate to the value of dtfileclosed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I managed to get your data step results with the following code in SQL also:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dtfileclosed :datetime23.3 dtqueryresolveddate :datetime23.3;
format dtfileclosed datetime23.3 dtqueryresolveddate datetime23.3;
cards;
. .
03oct2016:00:00:00.000 .
. 03oct2016:00:00:00.000
02oct2016:00:00:00.000 03oct2016:00:00:00.000
;
run;

data want1;
set have;
if dtfileclosed ne . then dtQueryResolvedDate=dtfileclosed;
if dtQueryResolvedDate = . then dtQueryResolvedDate="01JAN1900:00:00:00.000"dt;
if dtQueryResolvedDate = "01JAN1900:00:00:00.000"dt then resolved = 0; else resolved=1;
run;

proc print noobs;
run;

proc sql;
create table want2 as
select
  case
    when dtfileclosed ne . then dtfileclosed
    when dtQueryResolvedDate = . and dtfileclosed = . then "01JAN1900:00:00:00.000"dt
    else dtQueryResolvedDate
  end as dtQueryResolvedDate format=datetime23.3,
  case
    when calculated dtQueryResolvedDate ne "01JAN1900:00:00:00.000"dt then 1
    else 0
  end as resolved
from have;
quit;

proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;PRE&gt;          dtfileclosed        dtqueryresolveddate    resolved

                     .     01JAN1900:00:00:00.000        0   
03OCT2016:00:00:00.000     03OCT2016:00:00:00.000        1   
                     .     03OCT2016:00:00:00.000        1   
02OCT2016:00:00:00.000     02OCT2016:00:00:00.000        1   
                                                             

                dtQueryResolvedDate    resolved

             01JAN1900:00:00:00.000        0   
             03OCT2016:00:00:00.000        1   
             03OCT2016:00:00:00.000        1   
             02OCT2016:00:00:00.000        1   
&lt;/PRE&gt;
&lt;P&gt;Note that if you want to base a CASE statement on the result of another CASE, use "calculated" to distinguish the newly created value from the original database column.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 13:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302046#M20501</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-03T13:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302091#M20506</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, the calculated key word is SAS specific.</description>
      <pubDate>Mon, 03 Oct 2016 15:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302091#M20506</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-10-03T15:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302138#M20509</link>
      <description>&lt;P&gt;Your query appears to be using SQL Server Transact-SQL. There is no equivalent in SQL Server to SAS's missing values although IS NULL or IS NOT NULL may work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 19:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302138#M20509</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-03T19:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302269#M20511</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt; wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, the calculated key word is SAS specific.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, after all, this is the &lt;U&gt;SAS&lt;/U&gt; Communities website, so one should expect answers that work in SAS. If one has to deal with other software, there are surely forums for that.&lt;/P&gt;
&lt;P&gt;And if someone is tasked with migrating processes to a certain system, they should have sufficient knowledge for that system in the first place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2016 06:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-to-SQL/m-p/302269#M20511</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-04T06:33:33Z</dc:date>
    </item>
  </channel>
</rss>

