SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Bumble_15
Fluorite | Level 6

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!

2 REPLIES 2
Mazi
Pyrite | Level 9

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;
ballardw
Super User

@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;

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 2 replies
  • 677 views
  • 1 like
  • 3 in conversation