BookmarkSubscribeRSS Feed
anjgupta
Calcite | Level 5

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

3 REPLIES 3
Patrick
Opal | Level 21

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

Ksharp
Super User

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

ballardw
Super User

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?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 803 views
  • 0 likes
  • 4 in conversation