<?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: Proc Format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34661#M6831</link>
    <description>When posting content, data-volume is not usually an issue - what characters are posted is more of a concern (for truncation).  This previous post helps - recommend bookmarking it for future reference:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Tue, 16 Nov 2010 19:09:46 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-11-16T19:09:46Z</dc:date>
    <item>
      <title>Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34656#M6826</link>
      <description>Hi there.&lt;BR /&gt;
&lt;BR /&gt;
I'm trying to create a custom format for a datetime column. The result of aplying the format (label) should be a date value or missing in case the format value is out of range.&lt;BR /&gt;
My problem is when the value is out of range. Instead of setting it to missing, SAS just returns the value as is, not formated.&lt;BR /&gt;
The code is the following:&lt;BR /&gt;
&lt;BR /&gt;
data intervals;&lt;BR /&gt;
    retain fmtname 'myformat';&lt;BR /&gt;
    length start end 8;&lt;BR /&gt;
    informat start end datetime19.;&lt;BR /&gt;
    format start end datetime19.;&lt;BR /&gt;
    set syt10 end=last;&lt;BR /&gt;
    start=lag(datetimevalue);&lt;BR /&gt;
    end=datetimevalue;&lt;BR /&gt;
    label=lag(datevalue);&lt;BR /&gt;
    if _n_^=1 then&lt;BR /&gt;
        output;&lt;BR /&gt;
    if last then do;&lt;BR /&gt;
        start=end;&lt;BR /&gt;
        end='31dec2100:23:59:59'dt;&lt;BR /&gt;
        label=datevalue;&lt;BR /&gt;
        output;&lt;BR /&gt;
        start=.;&lt;BR /&gt;
        end=.;&lt;BR /&gt;
        hlo='O';&lt;BR /&gt;
        label= . ;&lt;BR /&gt;
        output;&lt;BR /&gt;
    end;&lt;BR /&gt;
    keep start end label hlo;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc format cntlin=intervals;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The procedure runs with no errors.&lt;BR /&gt;
Let's assume that the first datetime value on the input dataset (syt10) is '31oct2010:00:00:00'dt. Basically, what i need is that every value bellow that datetime is set to missing, and the rest to be set with the datevalue of their corresponding interval. All values in the intervals are well formated, but the ones bellow aren't.&lt;BR /&gt;
&lt;BR /&gt;
Look at this example output please:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
var='23oct2010:01:01:01'dt;&lt;BR /&gt;
varf=put(var,myformat.);&lt;BR /&gt;
put 'format result: ' varf;&lt;BR /&gt;
var='01nov2010:01:01:01'dt;&lt;BR /&gt;
varf=put(var,myformat.);&lt;BR /&gt;
put 'format result: ' varf;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
format result: 16E8&lt;BR /&gt;
format result: 18566&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
What am i doing wrong here?&lt;BR /&gt;
&lt;BR /&gt;
Regards in advance.</description>
      <pubDate>Tue, 16 Nov 2010 18:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34656#M6826</guid>
      <dc:creator>dropez</dc:creator>
      <dc:date>2010-11-16T18:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34657#M6827</link>
      <description>To start, your KEEP list is incomplete.  Must also have FMTNAME.  Suggest you unload your format using CNTLOUT= for review/verification against some "unformatted" data values in the file you are using with your PUT function.  Also, with your forum post, it's more useful to paste your SAS log, not just the program -- I have to wonder what SAS format was actually created, given you have no FMTNAME variable in the KEEP list.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 16 Nov 2010 18:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34657#M6827</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-16T18:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34658#M6828</link>
      <description>My original code is a bit more complex as i'm creating several formats from the same input table so I edited some of the code to be more perceptible and forgot to edit the keep part.&lt;BR /&gt;
I'll go for cntlout option and see if i can find the answear to my problem.&lt;BR /&gt;
&lt;BR /&gt;
Thks.</description>
      <pubDate>Tue, 16 Nov 2010 18:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34658#M6828</guid>
      <dc:creator>dropez</dc:creator>
      <dc:date>2010-11-16T18:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34659#M6829</link>
      <description>Consider that it does help to be forthright (or include some disclaimer) rather than wasting others' time, when posting incomplete or inaccurate material. Which is exactly the reason why I would suggest SAS log (with all SAS code revealed) rather than code-piece, whether or not it's complete.  Just a thought for next time.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 16 Nov 2010 18:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34659#M6829</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-16T18:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34660#M6830</link>
      <description>I'm sorry if i wasted your time in anyway. The goal in simplyfing the question was exactly the opposite, so you wouldn't have to be understanding very complex code to answear a simple question.&lt;BR /&gt;
Next time i'll put you all code and log here, even if it takes four or five posts to do so.</description>
      <pubDate>Tue, 16 Nov 2010 18:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34660#M6830</guid>
      <dc:creator>dropez</dc:creator>
      <dc:date>2010-11-16T18:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34661#M6831</link>
      <description>When posting content, data-volume is not usually an issue - what characters are posted is more of a concern (for truncation).  This previous post helps - recommend bookmarking it for future reference:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 16 Nov 2010 19:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34661#M6831</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-16T19:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34662#M6832</link>
      <description>It is now bookmarked, thank you.</description>
      <pubDate>Tue, 16 Nov 2010 19:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34662#M6832</guid>
      <dc:creator>dropez</dc:creator>
      <dc:date>2010-11-16T19:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34663#M6833</link>
      <description>When we ask for simplification what we need is essential code - the part that you think is giving you the problem.  That helps us home in on the true issue.  I suspect that there is more than one.  A couple potential ones have already been identified.  Here is a 'simple' format that may answer a couple of the questions.&lt;BR /&gt;
&lt;BR /&gt;
Notice the KEEP= option and especially the use of the HLO variable to allow a nested format.  Finally I included some dummy data to test the format.&lt;BR /&gt;
&lt;BR /&gt;
[pre]data intervals(keep=fmtname start end label hlo);&lt;BR /&gt;
retain fmtname 'myfmt';&lt;BR /&gt;
start = '12jan2000:01:01:01'dt;&lt;BR /&gt;
end = '24nov2005:11:12:13'dt;&lt;BR /&gt;
label = 'datetime18.';&lt;BR /&gt;
hlo = 'F';&lt;BR /&gt;
output;&lt;BR /&gt;
start=.;&lt;BR /&gt;
end=.;&lt;BR /&gt;
hlo='O';&lt;BR /&gt;
label= '.' ;&lt;BR /&gt;
output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc format cntlin=intervals;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data tryit;&lt;BR /&gt;
value= '10jan2000:01:01:01'dt; put 'Below range ' value= datetime. value=myfmt.;&lt;BR /&gt;
value= '10jan2004:01:01:01'dt; put 'In range ' value= datetime. value=myfmt.;&lt;BR /&gt;
value= '10jan2006:01:01:01'dt; put 'After range ' value= datetime. value=myfmt.;&lt;BR /&gt;
run;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
When writing a format using a control data set it is sometimes helpful to know some of the values that can be taken on by the supporting variables, such as HLO.  I sometimes write a dummy format using the VALUE or INVALUE statement and then print out the data set:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format ;&lt;BR /&gt;
value testdt&lt;BR /&gt;
 low- &amp;lt; '01jan2011'd = 'early'&lt;BR /&gt;
 '01jan2011'd - '01jan2012'd = [date9.]&lt;BR /&gt;
 other = 'unk';&lt;BR /&gt;
 run;&lt;BR /&gt;
 proc format cntlout=testdt(where=(fmtname='TESTDT'));&lt;BR /&gt;
 run;&lt;BR /&gt;
 proc print data=testdt;&lt;BR /&gt;
 run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 17 Nov 2010 05:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format/m-p/34663#M6833</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-11-17T05:25:10Z</dc:date>
    </item>
  </channel>
</rss>

