Help inputting "<1" as a number?

Reply
Occasional Contributor
Posts: 10

Help inputting "<1" as a number?

I have a raw data I'm trying to input, but I cannot figure out how to input <1 as a number. This is a snippet of how two lines of the raw data look:

"...k  103  270  140  15.0  10.0  0  60  170  31  0  21  4  2011   

Van....

........es  101  270  140  15.0  7.0  0  60  105  30  <1  23  4 ........ "

Super Contributor
Posts: 543

Re: Help inputting "<1" as a number?

I think you need to read in the numbers as "characters"

data in;

input letter $ v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 $ v11 v12;

cards;

k  103  270  140  15.0  10.0  0  60  170  31 0  21  4

es  101  270  140  15.0  7.0  0  60  105  30  <1  23  4

;

Because the '<' sign is a character, SAS will read it right only if the entire variable is character.

It's late here, maybe I am not making sense.

If you don't know which variable has the "<1" values then you may need to read all you variables in as characters.

Just a thought.

Anca.

Respected Advisor
Posts: 3,124

Re: Help inputting "<1" as a number?

"<1" is not a number, not only it is char, but also if it implies number, it implies many numbers which are less than 1. Question is: if you do want to input "<1" as a number, you need to decide which number you want to assign to it. If you made a decision that "<1" will be input as , for example, 0.5, then you could try the following:

proc format;

  invalue num

     '<1' = 0.5;

run;

data want;

  input v1-v3 v4 num.;

  put v4=;

  cards;

  1 2 3 <1

  ;

Haikuo

Respected Advisor
Posts: 4,644

Re: Help inputting "<1" as a number?

I agree with Anca. You can't avoid reading such data as character. In some cases, you may also want to put something else as a number for values <n, such as n/2... If any of these fields can start with "<", use arrays :

data test;
length car1 cv1-cv13 car2 $10;
array cv{13};
array v{13};
input car1 cv1-cv13 car2;
do i = 1 to dim(v);
if first(cv{i}) = "<" then v{i} = input(substr(cv{i},2), best.);
else v{i} = input(cv{i}, best.);
end;
drop cv: i;
datalines;
...k  103  270  140  15.0  10.0  0  60  170  31  0  21  4  2011    Van....
........es  101  270  140  15.0  7.0  0  60  105  30  <1  23  4 2012 .....dum
;

proc print; run;

PG

PG
Super User
Posts: 9,676

Re: Help inputting "<1" as a number?

Or use ?? input modifier .

Ask a Question
Discussion stats
  • 4 replies
  • 170 views
  • 0 likes
  • 5 in conversation