Help using Base SAS procedures

What is wrong with this informat?

Reply
New Contributor
Posts: 3

What is wrong with this informat?

proc format;

  invalue $newdate     '01JAN1990'd - '31DEC2004'd = 'Too Early'

                                '01JAN2005'd - '31DEC2005'd = [mmddyy10.]       

                                '01JAN2007'd - high = 'Too Late';

run;

After running this, I kept getting the following error:

ERROR: These two ranges overlap: '01JAN1990'd-'31DEC2004'd and '01JAN2007'd-HIGH (fuzz=0).

ERROR: These two ranges overlap: '01JAN2007'd-HIGH and '01Jan2005'd-'31DEC2005'd (fuzz=0).

Thanks.

PROC Star
Posts: 7,492

What is wrong with this informat?

Posted in reply to Southwind

I can't test it at the moment, but will the error go away if you replace - with <-

Art

Respected Advisor
Posts: 3,799

What is wrong with this informat?

Posted in reply to Southwind

You don't want an INFORMAT you want a FORMAT.  Then use a FORMAT statement to format the date variable. 

proc format;

  value newdate    

      '01JAN1990'd - '31DEC2004'd = 'Too Early'

      '01JAN2005'd - '31DEC2005'd = [mmddyy10.]       

      '01JAN2007'd - high = 'Too Late';

   run;

PROC Star
Posts: 7,492

What is wrong with this informat?

Posted in reply to data_null__

I'm sure that data_null has already provided the correct answer but, while you make the change, is there a reason why you don't include 2006 in your ranges?

New Contributor
Posts: 3

What is wrong with this informat?

Posted in reply to Southwind

I can make the code work by using FORMAT.

Just one more question, why can I not use INFORMAT here?

* To Art297: The range should be till the end of 2006. Thanks for pointing that out.

Respected Advisor
Posts: 3,799

Re: What is wrong with this informat?

Posted in reply to Southwind

Southwind wrote:

I can make the code work by using FORMAT.

Just one more question, why can I not use INFORMAT here?



The INFORMAT code in your first post using the SAS date constant implies that you HAVE a variable that is a SAS DATE you want to display in a specific way.  If that is not correct you need to be specific about what you have and what you want not just "what's wrong with this"...

Given that I believe your starting point in a SAS DATE and you want to display Too Early, Too Late or MMDDYY you need a FORMAT not an INFORMAT.

You could write a Rube Goldberg Machine http://en.wikipedia.org/wiki/Rube_Goldberg_machine program using an INFORMAT but that would be silly.

Super User
Posts: 10,046

Re: What is wrong with this informat?

Posted in reply to Southwind

It is very interesting.

It looks like that proc format does not recognize the date constant '01jan2001'd ,when I use number of date to instead of '01jan2001'd. the code passed.

proc format;
    invalue                        $ newdate
  10958 - 12000 = 'Too Early'
  16000 - high = 'Too Late';
run;
data xx;
 do date='01jan1990'd to '01jan2011'd;
  output;
 end;
 format date mmddyy10.;
run;

Ksharp

Message was edited by: xia keshan

New Contributor
Posts: 3

Re: What is wrong with this informat?

data xx;

input date $newdate20.;

datalines;

31JAN1990

;

run;

proc print data=xx;

run;

Thank you Ksharp. I tested and it worked like charm.Smiley Happy

Super User
Super User
Posts: 7,077

Re: What is wrong with this informat?

Posted in reply to Southwind

The two main problems I see with doing what I think you want to do with an INFORMAT are what you are inputting and what you are outputting.

You are attempting to define a character informat but the MMDDYY format is a numeric format. It outputs a numeric date not a character string.

You are attempting to define the inputs as date constants, but informats need character strings as inputs.  That is why it complains about overlapping ranges.  '01JAN1990' is less than '01JAN2007' which is less than '31DEC2004' because '19' < '20' and '31' > '01'.

Ask a Question
Discussion stats
  • 8 replies
  • 510 views
  • 3 likes
  • 5 in conversation