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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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

PG
NKormanik
Barite | Level 11

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;



Haikuo
Onyx | Level 15

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

NKormanik
Barite | Level 11

_xcellent.  I'll give it a try, Haikuo.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1506 views
  • 3 likes
  • 3 in conversation