<?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: converting datetime20 to yyyymmdd in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488645#M31575</link>
    <description>&lt;P&gt;There is no silver bullet for this. You need to identify the columns (eg by looking for certain attributes in dictionary.columns) and then apply the suggested method in dynamically created code, if you want to automate this conversion.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2018 17:31:33 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-08-21T17:31:33Z</dc:date>
    <item>
      <title>converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488613#M31571</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I using a pass through connection to connect to an oracle Table as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CXNOracle(user=, password=, path=, schema=);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;CONNECT to oracle as oradb&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(user=&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;user.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; password=&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;password.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; path=&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;path.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; );&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;create table &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;GFileName.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM connection to oradb&lt;/P&gt;&lt;P&gt;(SELECT *&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;FROM &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;schema.&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;GFileName.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DISCONNECT from oradb;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%Mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CXNOracle;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;CXNOracle&lt;/I&gt;&lt;/STRONG&gt;(user=*****, password=****, path=*****, schema=****);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, I input my user name, password, the place where is the oracle table then a schema.&lt;/P&gt;&lt;P&gt;The FileName is defined as a global variable as GFileName.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have let's six date variable with the datetime20 format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The challenge is to convert all date variables from a datetime20 format to YYYYMMDD without naming the variable.&lt;/P&gt;&lt;P&gt;Is there a way to set all date variables to a default format ex: YYYYMMDD?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date variable as the following format = 31JAN1966:00:00:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help.&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>Tue, 21 Aug 2018 15:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488613#M31571</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2018-08-21T15:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488620#M31572</link>
      <description>&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datevar = datepart(datevar);
format datevar yymmddn8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or in a SQL select&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datepart(datevar) as datevar format=yymmddn8.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 15:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488620#M31572</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-21T15:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488627#M31573</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I have mentioned, I calling the oracle table only by their name.&amp;nbsp; Some table may have two date variables other six date variables and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am looking for is a way to convert all date variables to YYYYMMDD in one shot without having to format all date variable one by one, like a default format for date variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does your code will do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 15:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488627#M31573</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2018-08-21T15:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488643#M31574</link>
      <description>&lt;P&gt;Please check, either by proc contents or by sql, selecting dictionary.columns - do the datetime variables have a format of datetime20. as you mentioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If positive, it is possible to identify those variables through their format, convert then to date variables and reformat them,&lt;/P&gt;
&lt;P&gt;to be done either by data step or by a macro, without renaming them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 17:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488643#M31574</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-08-21T17:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488645#M31575</link>
      <description>&lt;P&gt;There is no silver bullet for this. You need to identify the columns (eg by looking for certain attributes in dictionary.columns) and then apply the suggested method in dynamically created code, if you want to automate this conversion.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 17:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/488645#M31575</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-21T17:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/705117#M37854</link>
      <description>Wonderful - Thanks</description>
      <pubDate>Thu, 10 Dec 2020 16:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/705117#M37854</guid>
      <dc:creator>abqdiane</dc:creator>
      <dc:date>2020-12-10T16:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: converting datetime20 to yyyymmdd</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/705127#M37855</link>
      <description>&lt;P&gt;Use the FMTINFO() function to find the DATETIME variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use something similar to the answer to this question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Change-DATE-formats-to-DDMMYYS10-for-ALL-unknown-number-date/td-p/366637" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Change-DATE-formats-to-DDMMYYS10-for-ALL-unknown-number-date/td-p/366637&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro CXNOracle(user=, password=, path=, schema=);
%if %symexist(gfilename) %then %do;
  %if %length(&amp;amp;gfilename) %then %do;  

libname oradb oracle user=&amp;amp;user password=&amp;amp;password path=&amp;amp;path schema=&amp;amp;schema access=readonly ;
proc contents data=oradb.&amp;amp;gfilename noprint out=_contents; run;
filename oracode temp;
data _null_;
  if 0=nobs then put "ERROR: No variables found for &amp;amp;gfilename..";
  file oracode ;
  set _contents obs=nobs end=eof;
  if _n_=1 then put
      "date &amp;amp;gfilename(label='From &amp;amp;path..&amp;amp;schema..&amp;amp;gfilename')"
    / " set oradb." &amp;amp;gfilename ';'
  ;
  if fmtinfo(format,'cat')='datetime' then put
      name '=datepart(' name ');'
    / 'format ' name 'yymmdd10.;'
  ;
  if eof then put 'run;' ;
run;
%include oracode / source2 ;

%else %put ERROR: Macro variable GFILENAME is empty.;
%else %put ERROR: Macro variable GFILENAME does not exist.;
libname oradb clear ;
%mend CXNOracle;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Dec 2020 17:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-datetime20-to-yyyymmdd/m-p/705127#M37855</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-10T17:22:36Z</dc:date>
    </item>
  </channel>
</rss>

