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 ........ "
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.
"<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
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
Or use ?? input modifier .
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.
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.