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

## Creating a new variable

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

## Re: Creating a new variable

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

2 REPLIES 2
Super User

## Re: Creating a new variable

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

Calcite | Level 5

## Re: Creating a new variable

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

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