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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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