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.
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.
The code is the following:
retain fmtname 'myformat';
length start end 8;
informat start end datetime19.;
format start end datetime19.;
set syt10 end=last;
if _n_^=1 then
if last then do;
label= . ;
keep start end label hlo;
proc format cntlin=intervals;
The procedure runs with no errors.
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.
Look at this example output please:
put 'format result: ' varf;
put 'format result: ' varf;
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.
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.
I'll go for cntlout option and see if i can find the answear to my problem.
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.
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.
Next time i'll put you all code and log here, even if it takes four or five posts to do so.
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.
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.
value= '10jan2000:01:01:01'dt; put 'Below range ' value= datetime. value=myfmt.;
value= '10jan2004:01:01:01'dt; put 'In range ' value= datetime. value=myfmt.;
value= '10jan2006:01:01:01'dt; put 'After range ' value= datetime. value=myfmt.;
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:
proc format ;
low- < '01jan2011'd = 'early'
'01jan2011'd - '01jan2012'd = [date9.]
other = 'unk';
proc format cntlout=testdt(where=(fmtname='TESTDT'));
proc print data=testdt;