<?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: Datepart function in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719641#M222855</link>
    <description>&lt;P&gt;To have the format available, store it permanently where it is automatically picked up, e.g. in SASUSER:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=sasuser;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where you store it depends largely on your SAS setup and usage.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Feb 2021 14:10:05 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-02-16T14:10:05Z</dc:date>
    <item>
      <title>Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718382#M222327</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have a question about using DATEPART in PROC SQL.&lt;/P&gt;
&lt;P&gt;I have a table with timestamp like 25DEC20201:16:12:18 , informat Datetime28&lt;/P&gt;
&lt;P&gt;I wish to use the following Alter&amp;nbsp; table function in proc sql to modify the column. I don't want to use a data step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
Alter table test modify birthday=DATEPART(birthday) format =ddmmyy10.;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know the syntax is wrong, but can any one help with the correct syntax? As I mentioned earlier I will prefer using the modify column to achieve the desired result.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 20:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718382#M222327</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-10T20:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718390#M222332</link>
      <description>&lt;P&gt;It is probably going to be a lot easier to just make a NEW dataset that has the new information.&amp;nbsp; Also why use SQL?&lt;/P&gt;
&lt;P&gt;(Also why use either of DMY or MDY order for display dates? It will just confuse half of your audience)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set test;
  birthday=DATEPART(birthday) ;
  format birthday yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 20:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718390#M222332</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-10T20:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718439#M222350</link>
      <description>&lt;P&gt;MODIFY in a DB will not recreate the table, in SAS it still will so it doesn't matter if it's via modify or a new data set, the amount of work is the same behind the scenes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Since this is likely homework, you should check the SQL documentation for these statements and see how they're used. The section in orange is used to change the format. The section in purple is used to change the value.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0rdzn3mhqxl2zn13uvxkjkt1svq.htm&amp;amp;locale=en#n1g4qj33e7sosin0zg1tcmsbmpbh"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0rdzn3mhqxl2zn13uvxkjkt1svq.htm&amp;amp;locale=en#n1g4qj33e7sosin0zg1tcmsbmpbh&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
   title "World's Largest Countries";
   alter table sql.newcountries
      &lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;modify name char(60) format=$60.;&lt;/STRONG&gt;&lt;/FONT&gt;
   update sql.newcountries
      &lt;STRONG&gt;&lt;FONT size="4" color="#800080"&gt;set name='The United Nations member country is '||name;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does also need a quit at the end, but that should explain how you need to format your syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;P&gt;data stocks;&lt;BR /&gt;set sashelp.stocks;&lt;BR /&gt;date = dhms(date, 8, 4, 0);&lt;BR /&gt;format date datetime.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;alter table stocks&lt;BR /&gt;modify date format=ddmmyy10.;&lt;BR /&gt;update stocks&lt;BR /&gt;set date = datepart(date);&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc contents data=stocks;&lt;BR /&gt;run;&lt;/P&gt;
&lt;/LI-SPOILER&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>Wed, 10 Feb 2021 23:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718439#M222350</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-10T23:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718441#M222351</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dataset &lt;FONT face="courier new,courier"&gt;test&lt;/FONT&gt; is very large and you just want to change the &lt;EM&gt;format&lt;/EM&gt; of variable &lt;FONT face="courier new,courier"&gt;birthday&lt;/FONT&gt; from, e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;datetime19.&lt;/FONT&gt; to something that looks like &lt;FONT face="courier new,courier"&gt;ddmmyy10.&lt;/FONT&gt;, then, indeed, you may want to use the ALTER TABLE statement in PROC SQL (or the MODIFY statement of PROC DATASETS) so that the large dataset is neither read nor rewritten. But you would just alter&amp;nbsp;the &lt;EM&gt;meta&lt;/EM&gt;data rather than create a new variable using the DATEPART function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture dtdmy
low-high='%0d/%0m/%Y' (datatype=datetime);
run;

proc sql;
alter table test
modify birthday format=dtdmy.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I haven't found a suitable SAS-supplied format, therefore created a new one. Feel free to modify the format definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited after replies by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;: Changed "&lt;FONT face="courier new,courier"&gt;other&lt;/FONT&gt;" to "&lt;FONT face="courier new,courier"&gt;low-high&lt;/FONT&gt;" in the format definition so as to avoid issues with missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 08:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718441#M222351</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-11T08:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718448#M222354</link>
      <description>That's a great idea! For most formats there's a DT version, ie DTDATE9 will apply the date9 format to a datetime variable. You can also control it sometimes by modifying the length, ie DATETIME7. is equivalent to Date7.  &lt;BR /&gt;&lt;BR /&gt;But the format of dd/mm/yy isn't commonly used, so none of those tricks work by default in the exact use case here.</description>
      <pubDate>Thu, 11 Feb 2021 01:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718448#M222354</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-11T01:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718491#M222371</link>
      <description>@FreelanceReinhard&lt;BR /&gt;It worked quiet fine but the problem is that, it writes in missing fields ERROR as text. Is there any way to correct that?</description>
      <pubDate>Thu, 11 Feb 2021 07:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718491#M222371</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-11T07:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718498#M222376</link>
      <description>&lt;P&gt;You need to take care of missing values in the definition of the format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input birthday datetime25.;
format birthday datetime25.;
datalines;
25DEC2020:16:12:18
.
;

proc format;
picture dtdmy
  . = "."
  other='%0d/%0m/%Y' (datatype=datetime)
;
run;

proc sql;
alter table have
modify birthday format=dtdmy.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 07:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718498#M222376</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-11T07:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718501#M222377</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;BR /&gt;Thanks, it worked</description>
      <pubDate>Thu, 11 Feb 2021 08:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718501#M222377</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-11T08:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718508#M222381</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;: Sorry that I had overlooked that weakness in my original format definition. Thanks for pointing out that SAS creates the really unusual formatted value "&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ERROR&lt;/FONT&gt;" (with five leading blanks) for missing values in this situation. And thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;for providing the fix. Another way of fixing it is to use &lt;FONT face="courier new,courier"&gt;low-high&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;other&lt;/FONT&gt;&amp;nbsp;in the PROC FORMAT step. As a bonus, this also handles special missing values (&lt;FONT face="courier new,courier"&gt;._&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;.a&lt;/FONT&gt; , ..., &lt;FONT face="courier new,courier"&gt;.z&lt;/FONT&gt;) in a satisfactory way. I've edited my original reply so that later readers of this thread won't run into those "ERROR" messages (in the &lt;EM&gt;output&lt;/EM&gt;).&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 09:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718508#M222381</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-11T09:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718535#M222392</link>
      <description>That also works perfectly, thankyou</description>
      <pubDate>Thu, 11 Feb 2021 11:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718535#M222392</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-11T11:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718980#M222540</link>
      <description>@FreelanceReinhard; @KurtBrenser&lt;BR /&gt;Hi, there is a problem I realise. I can't open the table without having to run the code. I get this error message:&lt;BR /&gt;ERROR: Format dtdmy not found or couldn't be loaded for variable birthday. Is there any correction to this.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Feb 2021 19:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/718980#M222540</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-12T19:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719641#M222855</link>
      <description>&lt;P&gt;To have the format available, store it permanently where it is automatically picked up, e.g. in SASUSER:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=sasuser;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where you store it depends largely on your SAS setup and usage.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 14:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719641#M222855</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-16T14:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719654#M222862</link>
      <description>&lt;P&gt;My apologies,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;, your reply escaped my attention somehow. Thanks again to Kurt Bremser for stepping in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Indeed, user-defined formats and informats that are permanently associated with variables in permanent datasets need to be available when working with these datasets. (System option &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lesysoptsref&amp;amp;docsetTarget=p1djbl02hfnoe3n0zh2i3uu2aqrf.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;NOFMTERR&lt;/A&gt; is a quick remedy, but of course cannot provide the missing [in]format definition.) The format catalogs searched for&amp;nbsp;user-defined formats and informats are determined by the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lesysoptsref&amp;amp;docsetTarget=p1fvn6rwmpf1njn1whkud1hmsc97.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FMTSEARCH= system option&lt;/A&gt;, whose default value is&lt;/P&gt;
&lt;PRE&gt;(WORK LIBRARY)&lt;/PRE&gt;
&lt;P&gt;That is, after the (temporary) WORK format catalog of the current SAS session the catalog LIBRARY.FORMATS will be searched if the search in WORK.FORMATS was unsuccessful &lt;EM&gt;and&lt;/EM&gt; the libref LIBRARY has been assigned. Since LIBRARY.FORMATS will &lt;EM&gt;always&lt;/EM&gt; be searched (regardless of the FMTSEARCH setting), you can store the format definition in an arbitrary permanent library (e.g., your project library if the format is project-specific) and then use a LIBNAME statement to assign libref LIBRARY to that physical location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Program containing the format definition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname proj 'D:\Projects\XYZ2021\sasdata';

...

proc format lib=proj;
picture dtdmy
low-high='%0d/%0m/%Y' (datatype=datetime);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Program using the format itself or a dataset containing a variable that format DTDMY. has been associated&amp;nbsp;with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname library 'D:\Projects\XYZ2021\sasdata';

...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Often there's already an existing libref for that physical path, say, &lt;FONT face="courier new,courier"&gt;plib&lt;/FONT&gt;. Then you can also use this in the LIBNAME statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname plib 'D:\Projects\XYZ2021\sasdata';
libname library (plib);

...&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 15:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719654#M222862</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-16T15:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719702#M222871</link>
      <description>Thankyou very much</description>
      <pubDate>Tue, 16 Feb 2021 19:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719702#M222871</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-16T19:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Datepart function in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719703#M222872</link>
      <description>Thanks alot for the reply</description>
      <pubDate>Tue, 16 Feb 2021 19:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datepart-function-in-proc-sql/m-p/719703#M222872</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-02-16T19:09:32Z</dc:date>
    </item>
  </channel>
</rss>

