DATA Step, Macro, Functions and more

if a value is defined two formats, which one will it take?

Reply
Frequent Contributor
Posts: 133

if a value is defined two formats, which one will it take?

Is following allowed? looks ok, but 4 is defined twice in format, the result is using homie, not mid.

Can someone help explain?

proc format;

    value ne

        low -  4 = 'homie'

        4 - 8 = 'mid';

run;

data t;

    input amt;

    cards;

    4

    5

    ;

proc print data=t;

    format amt ne.;

run;

Super Contributor
Posts: 276

Re: if a value is defined two formats, which one will it take?

I thought Mid will be displayed in the place of 4.

Because 4-8='mid' is the recent value in proc format.

So this is going to apply to "4"..

Regards..

Sanjeev.k

Occasional Contributor RLC
Occasional Contributor
Posts: 9

Re: if a value is defined two formats, which one will it take?

Posted in reply to kuridisanjeev

The best response is to submit yours statements and consult the ouptut...

Another idea... submit these 2 statements

format cntlout=poub ;run;

print label ;var fmtname start end sexcl eexcl;run;

Ouptut

                             Ending

Format   Starting value   value for    Start       End

name     for format       format       exclusion   exclusion

  NE         LOW              4          N          N

  NE          4               8          Y          N

Respected Advisor
Posts: 4,173

Re: if a value is defined two formats, which one will it take?

Without testing I would have expected that an error gets thrown because of overlapping ranges. But no: Proc Format digests these overlapping values.

On my SAS9.3 Win64 installation the label from the lower range is taken independently in what order the ranges are defined with Proc Format (so it's always 'homie').

Wouldn't have thought about writing the format to a data set like RLC did. It's quite nice as it actually gives you an idea of what Proc Format does to deal with such an ambiguity.

Ask a Question
Discussion stats
  • 3 replies
  • 581 views
  • 0 likes
  • 4 in conversation