## Where Statement

Solved
Occasional Contributor
Posts: 19

# Where Statement

[ Edited ]

This minimal working example is supposed to generate "temp" with "x" from 0.1 to 0.9 by 0.1, and separates it observation by observation from "temp1" to "temp9," but SAS works well with x∈{1,2,4,5,6,7}, while it doesn't with x∈{3,8,9}. I cannot even guess what's wrong with this code since it's too simple.

``````data temp;
do x=0.1 to 0.9 by 0.1;
output;
end;
run;

%macro separate;

%do x=1 %to 9;

/*--------------------------------------------------
This only works with x in 1, 2, 4, 5, 6 and 7.
--------------------------------------------------*/
data temp&x.;
set temp;
where x=0.&x.;
run;

%end;

%mend;

%separate;

quit;``````

Thanks in advance. By the way, I tried if instead of where, but the result was same.

Accepted Solutions
Solution
‎04-20-2018 12:39 AM
PROC Star
Posts: 2,311

## Re: Where Statement

[ Edited ]

Run this:

``````data t;
set temp;
A=X-round(X,0.1);
format A 32.16;
run;``````

X                    A
0.1   0.0000000000000000
0.2   0.0000000000000000
0.3   0.0000000000000001
0.4   0.0000000000000000
0.5   0.0000000000000000
0.6   0.0000000000000000
0.7   0.0000000000000000
0.8  -0.0000000000000001
0.9  -0.0000000000000001

All has been said already. Time to learn how computers work.

All Replies
Solution
‎04-20-2018 12:39 AM
PROC Star
Posts: 2,311

## Re: Where Statement

[ Edited ]

Run this:

``````data t;
set temp;
A=X-round(X,0.1);
format A 32.16;
run;``````

X                    A
0.1   0.0000000000000000
0.2   0.0000000000000000
0.3   0.0000000000000001
0.4   0.0000000000000000
0.5   0.0000000000000000
0.6   0.0000000000000000
0.7   0.0000000000000000
0.8  -0.0000000000000001
0.9  -0.0000000000000001

All has been said already. Time to learn how computers work.

Occasional Contributor
Posts: 19

## Re: Where Statement

Thank you, Chris. I modified the original code.

``````data temp;
do x=0.1 to 0.9 by 0.1;
output;
end;
run;

%macro separate;

%do x=1 %to 9;

data temp&x.;
set temp;
where round(x,0.1)=0.&x.;
run;

%end;

%mend;

%separate;

quit;``````

With no reason I thought that there is no numerical concern in SAS as it displays 0.3 rather than 0.3000000000000001. I'd better be more careful if it's a float type.

☑ This topic is solved.