I'm using Proc G3Grid. Unfortunately in my data set there are violations of the following:
"If more than one observation in the input data set has the same values for both horizontal variables, x and y, a warning message is printed, and only the first such point is used in the interpolation."
Therefore, I'd like to add a teeny tiny bit of randomness to those variables.
For instance, if the original value is 5, I'd like to change that to 5.0000014738.
etc.
Can someone please show the appropriate code to do this? I'd like the changes to be "in place," as opposed to creating new variables.
Thanks much.
Nicholas Kormanik
If you don't mind moving all your points by tiny amounts, you could do :
data want;
call streaminit(7567);
set have;
x = x + (rand("UNIFORM")-0.5) * 0.00001;
run;
If, on the other hand, you want to move only duplicated points, but you know
that such points are consecutive in your dataset, you could do :
data want;
call streaminit(7567);
set have; by x y notsorted;
if not first.y then x = x + (rand("UNIFORM")-0.5) * 0.00001;
run;
PG
If you don't mind moving all your points by tiny amounts, you could do :
data want;
call streaminit(7567);
set have;
x = x + (rand("UNIFORM")-0.5) * 0.00001;
run;
If, on the other hand, you want to move only duplicated points, but you know
that such points are consecutive in your dataset, you could do :
data want;
call streaminit(7567);
set have; by x y notsorted;
if not first.y then x = x + (rand("UNIFORM")-0.5) * 0.00001;
run;
PG
Thanks PG. Your first example would be my present case. I have a follow-up on this. Please advise:
If I have many columns of data and not just one, and I want to do the same to each and every column, is there a way to do that?
If there is not a shortcut way of changing more than one of the, say, 100 variables, the following is, I suppose, what I'd have to do.
data want;
call streaminit(7567);
set have;
x1 = x1 + (rand("UNIFORM")-0.5) * 0.00001;
x2 = x2 + (rand("UNIFORM")-0.5) * 0.00001;
x3 = x3 + (rand("UNIFORM")-0.5) * 0.00001;
x4 = x4 + (rand("UNIFORM")-0.5) * 0.00001;
x5 = x5 + (rand("UNIFORM")-0.5) * 0.00001;
x6 = x6 + (rand("UNIFORM")-0.5) * 0.00001;
.
.
.
x100 = x100 + (rand("UNIFORM")-0.5) * 0.00001;
run;
Since PG is leaving the forum indefinitely, https://communities.sas.com/people/PGStats/activity
I will answer this one for him, not necessarily as good, but hopefully workable:
data want;
call streaminit(7567);
set have;
array _x x1-x100;
do over _x;
_x = _x + (rand("UNIFORM")-0.5) * 0.00001;
end;
run;
Haikuo
_xcellent. I'll give it a try, Haikuo.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.