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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

 

and read about numeric precision in SAS (and elsewhere).

 

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

 

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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

 

and read about numeric precision in SAS (and elsewhere).

 

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

 

Junyong
Pyrite | Level 9

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1248 views
  • 1 like
  • 2 in conversation