Hello,
I have a dataset with a variable "age" that is continuous, but contains "<1". I am looking to replace the "<1" with a range of numeric values (0.3-0.7). The data I have is for individuals and looks like:
data have; input individual age visit; datalines; 1 <1 1 1 12 2 1 13 3 2 <1 1 2 4 2 2 5 3 3 <1 1 4 <1 1 5 <1 1 6 3 1 7 9 1 8 <1 1 ; run;
I can't seem to figure out what code may work. I initially though proc MI but that may be overcomplicating the situation?
Thank you!
Can you give us more info on what your imputation rules are?
This example uses the rand function. If you can provide your imputation rules, we can advise better
data have;
input individual age $ visit;
datalines;
1 <1 1
1 12 2
1 13 3
2 <1 1
2 4 2
2 5 3
3 <1 1
4 <1 1
5 <1 1
6 3 1
7 9 1
8 <1 1
;
run;
data want;
set have;
if age = "<1" then age2 = rand('uniform', 0.3, 0.7);
else age2=input(age,best.);
run;
@Bumble_15 wrote:
Hello,
I have a dataset with a variable "age" that is continuous, but contains "<1". I am looking to replace the "<1" with a range of numeric values (0.3-0.7). The data I have is for individuals and looks like:
data have; input individual age visit; datalines; 1 <1 1 1 12 2 1 13 3 2 <1 1 2 4 2 2 5 3 3 <1 1 4 <1 1 5 <1 1 6 3 1 7 9 1 8 <1 1 ; run;I can't seem to figure out what code may work. I initially though proc MI but that may be overcomplicating the situation?
Thank you!
That description is not very clear. Do you want to replace some of the <1 with a single value of 0.3, and others with a single value of 0.4, 0.5 (or other single numeric values) or do want the <1 to display in printed output as (0.3-0.7)?
The latter display option would be to use a custom format.
If you want to randomly assign a numeric value in the range of 0.3 to 0.7 then questions come up about how many decimals do you want to allow in that range. The RAND function with the UNIFORM option will create numeric values in an interval.
data junk; do i=1 to 25; x=rand('uniform',.03,.07) ; output; end; run;
Round the values if you don't want lots of decimals.
To convert your existing data: (You would have to read age a character to get a value like "<1")
data have; input individual age $ visit; datalines; 1 <1 1 1 12 2 1 13 3 2 <1 1 2 4 2 2 5 3 3 <1 1 4 <1 1 5 <1 1 6 3 1 7 9 1 8 <1 1 ; data want; set have; if age='<1' then agenum= rand('UNIFORM',0.3,0.7); else agenum = input(age,2.); run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.