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!
@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 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.
@ballardw Thank you so much, that worked. I see what I did wrong there!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.