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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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