BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
akbarlam
Calcite | Level 5

Hi everyone,

I'm a new SAS user and researcher. I'm working with environmental contaminant data and trying to impute at 0.5*LOD (limit of detection). For example, I have my contaminant variable - pcb99. For this variable, I'd like to impute 0.5*0.03 for all sample values that fall below the detection limit of 0.03. All values above the DL would remain the same.

 

 Originally I was going to use proc MI (multiple imputation), but I believe that's only for missing values. I was wondering if I could get some help with the coding for creating a *new* variable imputing 0.015 for all values below the DL (0.03).

 

I've tried:

data set2;
set set1;

pcb99=pcb99DL;
if pcb99DL<0.03 then pcb99DL=0.015;

run;

This imputes all values as 0.015. 

I would greatly appreciate any help, thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@akbarlam wrote:

Hi everyone,

I'm a new SAS user and researcher. I'm working with environmental contaminant data and trying to impute at 0.5*LOD (limit of detection). For example, I have my contaminant variable - pcb99. For this variable, I'd like to impute 0.5*0.03 for all sample values that fall below the detection limit of 0.03. All values above the DL would remain the same.

 

 Originally I was going to use proc MI (multiple imputation), but I believe that's only for missing values. I was wondering if I could get some help with the coding for creating a *new* variable imputing 0.015 for all values below the DL (0.03).

 

I've tried:

data set2;
set set1;

pcb99=pcb99DL;
if pcb99DL<0.03 then pcb99DL=0.015;

run;

This imputes all values as 0.015. 

I would greatly appreciate any help, thank you!

 


If the variable pcb99dl does not already exist in your data set Set1 then you have 1) replaced all the values of pcb99 with missing values. Also all the initial values of pcb99dl would be missing. SAS treats missing values as the smallest value, i.e. less than any value and so would always be less than 0.03. I suspect that you might want something more like:

data set2;
set set1;

pcb99dl=pcb99;
if 0 < pcb99DL<0.03 then pcb99DL=0.015;

run;

 The 0 < pcb99dl < 0.03 would only assign a value of 0.015 when something was in the range. I am assuming that your particular measure can't have negative values when present. If you do want to assign 0.015 when the measurement is missing (again assuming if it ever is missing) then remove the " 0 < " bit.

 

In an assignment statement the variable that receives the value is the one on the LEFT side of the equal sign.

View solution in original post

2 REPLIES 2
ballardw
Super User

@akbarlam wrote:

Hi everyone,

I'm a new SAS user and researcher. I'm working with environmental contaminant data and trying to impute at 0.5*LOD (limit of detection). For example, I have my contaminant variable - pcb99. For this variable, I'd like to impute 0.5*0.03 for all sample values that fall below the detection limit of 0.03. All values above the DL would remain the same.

 

 Originally I was going to use proc MI (multiple imputation), but I believe that's only for missing values. I was wondering if I could get some help with the coding for creating a *new* variable imputing 0.015 for all values below the DL (0.03).

 

I've tried:

data set2;
set set1;

pcb99=pcb99DL;
if pcb99DL<0.03 then pcb99DL=0.015;

run;

This imputes all values as 0.015. 

I would greatly appreciate any help, thank you!

 


If the variable pcb99dl does not already exist in your data set Set1 then you have 1) replaced all the values of pcb99 with missing values. Also all the initial values of pcb99dl would be missing. SAS treats missing values as the smallest value, i.e. less than any value and so would always be less than 0.03. I suspect that you might want something more like:

data set2;
set set1;

pcb99dl=pcb99;
if 0 < pcb99DL<0.03 then pcb99DL=0.015;

run;

 The 0 < pcb99dl < 0.03 would only assign a value of 0.015 when something was in the range. I am assuming that your particular measure can't have negative values when present. If you do want to assign 0.015 when the measurement is missing (again assuming if it ever is missing) then remove the " 0 < " bit.

 

In an assignment statement the variable that receives the value is the one on the LEFT side of the equal sign.

akbarlam
Calcite | Level 5

@ballardw Thank you so much, that worked. I see what I did wrong there!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 397 views
  • 0 likes
  • 2 in conversation