BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am unable to get the RANPERM function to work in IML. I have used it successfully in a DATA step using an array, but it does not seem to work in IML on a matrix, even though SAS documentation says it should. For example, the code below produces no errors or warnings in the Log, yet has no effect on the matrix.

proc iml;
x={1,2,3};
seed=12;
call ranperm(seed,x);
print x;
quit;

Has anyone used this function successfully in IML?
2 REPLIES 2
Rick_SAS
SAS Super FREQ
As explained in a previous thread, some Base SAS functions such as RANPERM expect a list of arguments instead of a vector of arguments. See the thread
http://support.sas.com/forums/thread.jspa?threadID=7763&tstart=0

If you know that you have three objects to permute, you can use RANPERM like this:
proc iml;
x1=1; x2=2; x3=3;
seed=12; /* or use 0 for random seed */
call ranperm(seed,x1, x2, x3);
print x1, x2, x3;

However, there is an easy way to create a permutation of a vector of an arbitrary size: generate random uniform numbers and then compute the RANK of those numbers to use as an index vector. For example:

x = {1,2,3};
call randseed(12);
u = j(nrow(x),1); /* allocate vector */
do i = 1 to 5;
call randgen(u, "uniform"); /* fill u with random uniform */
perm = x[ rank(u) ]; /* use RANK(u) to permute data */
print i perm;
end;
deleted_user
Not applicable
Thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1043 views
  • 0 likes
  • 2 in conversation