<?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: Null Timestamp conversion macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661839#M197789</link>
    <description>&lt;P&gt;&lt;STRONG&gt;low-high&lt;/STRONG&gt; is perhaps what you need in the format instead of &lt;STRONG&gt;other&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

proc format ;
picture myfmt 
low-high= '%Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime )
other=.;
run;


data want;
dt=datetime();
output;
dt=.;
output;
format dt myfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Jun 2020 16:40:13 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-06-17T16:40:13Z</dc:date>
    <item>
      <title>Null Timestamp conversion macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661838#M197788</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying for a sas code for the conversion for data from the sas data set to have it in a txt file. If the target column data type is in timestamp , I'm changing the format&amp;nbsp; of that of timestamp column as in 'YYYY-MM-DD HH:MI:SS'. To achieve this I have used the below proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format ;&lt;BR /&gt;picture myfmt &lt;BR /&gt;other= '%Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime );&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dont see any problem with the above proc format. But from the source, I could see the null timestamp value in the sas data set ( as dot .) and after conversion step , the value for that timestamp column as 'ERROR' instead of dot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have used one more proc format as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format ;&lt;BR /&gt;value nmissfmt . = "." &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this my actual code for conversion for the timestamp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data WORK.test_1;&lt;BR /&gt;set WORK.test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i = 1 %to &amp;amp;obs;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%if &amp;amp;&amp;amp;target_type_name&amp;amp;i=TIMESTAMP %then %do; &lt;BR /&gt;%if %length(&amp;amp;&amp;amp;target_col_name&amp;amp;i)=0 %then %do;&lt;BR /&gt;format &amp;amp;&amp;amp;target_col_name&amp;amp;i nmissfmt.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;format &amp;amp;&amp;amp;target_col_name&amp;amp;i myfmt26.6;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But still Im getting value as ERROR on that column in the final dataset ( i.e. test_1). Is there any way to overcome this issue and also instead of using length , I tried initially with missing as like below, but ended up in error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if missing(&amp;amp;&amp;amp;target_col_name&amp;amp;i)=0 %then %do;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please advise me. Thanks in Advance.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 16:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661838#M197788</guid>
      <dc:creator>helannivas88</dc:creator>
      <dc:date>2020-06-17T16:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Null Timestamp conversion macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661839#M197789</link>
      <description>&lt;P&gt;&lt;STRONG&gt;low-high&lt;/STRONG&gt; is perhaps what you need in the format instead of &lt;STRONG&gt;other&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

proc format ;
picture myfmt 
low-high= '%Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime )
other=.;
run;


data want;
dt=datetime();
output;
dt=.;
output;
format dt myfmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jun 2020 16:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661839#M197789</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-17T16:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Null Timestamp conversion macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661840#M197790</link>
      <description>&lt;P&gt;You should only need one format. And since Format is a variable property you cannot assign it conditionally.&lt;/P&gt;
&lt;P&gt;Consider&lt;/P&gt;
&lt;PRE&gt;proc format ;
picture myfmt
low - high= '%Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime )
.  = '.'
;
run;&lt;/PRE&gt;
&lt;P&gt;Or have any desired text instead of '.' for the display value. I would likely use a blank but if your text file wants a dot to indicate missing the use that.&lt;/P&gt;
&lt;P&gt;The Low and High are special keywords for Proc Format values that mean the "smallest non-missing value" and and "the largest value".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 16:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/661840#M197790</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-17T16:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Null Timestamp conversion macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/662783#M197865</link>
      <description>&lt;P&gt;Thanks both!! It works perfectly.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jun 2020 05:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Null-Timestamp-conversion-macro/m-p/662783#M197865</guid>
      <dc:creator>helannivas88</dc:creator>
      <dc:date>2020-06-18T05:56:10Z</dc:date>
    </item>
  </channel>
</rss>

