BookmarkSubscribeRSS Feed
missmeliss22
Calcite | Level 5

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 ........ "

4 REPLIES 4
AncaTilea
Pyrite | Level 9

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.

Haikuo
Onyx | Level 15

"<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

PGStats
Opal | Level 21

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
Ksharp
Super User

Or use ?? input modifier .

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1234 views
  • 0 likes
  • 5 in conversation