Help using Base SAS procedures

Numeric collation with proc format and invalue?

Reply
Contributor
Posts: 47

Numeric collation with proc format and invalue?

Hello,

I've been asked to input all of my data as character and use PROC FORMAT with INVALUE to create new vars as numeric.  Some of this data has large ranges and I'd like to use, for instance:

invalue gramf

'227' - '8165' = _same_

other = .U;

run;

But I'm getting an error message "ERROR: Start is greater than end: -." due to how character vars are sorted by SAS, I believe.

I'd also like to ensure code such as:

invalue weight

'050' - '400' = _same_

other = .U;

doesn't give unexpected results due to the collation issue.

I've seen some info on NUMERIC_COLLATION but think it's only available for PROC SORT.

Any ideas?  I think the best solution is to read the data in as numeric - but might have to find a work around.

Thank you

Respected Advisor
Posts: 4,173

Re: Numeric collation with proc format and invalue?

From what I understand you best read the values as numeric. Code like below could help:

proc format;
   invalue gramf
      227 - 8165 = _same_
      other      = .U
   ;
run;

data test;
  input TestData gramf32.;
  format TestData best32.;
  datalines;
-40.5
0
226.9
227
500
1000.12345678
8165
8165.1
8166
.
;
run;

proc print data=test;
run;

HTH

Patrick

Super User
Posts: 10,035

Re: Numeric collation with proc format and invalue?

There is no need to make a informate for you situation.

data temp;
input gra $;
num_gra=input(gra, ?? best8.);
if num_gra lt 227 or num_gra gt 8165 or missing(num_gra) then num_gra=.U;
cards;
226
227
500
1000
8165
8165
8166
wioe
;
run;

Ksharp

Message was edited by: xia keshan

Super User
Posts: 11,343

Re: Numeric collation with proc format and invalue?

Since the code examples you provide do not generate the error it would be helpful to either post the whole PROC FORMAT code or the section that is creating the error.

What would be examples of unexpected results?

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