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

Hi, 

 

I have an interesting question that I would like to pose to you all.

 

I have a table of data that I pulled from an oracle server, and I need to randomly assign a vendor to each row of that table. I currently have a list of 5 vendors and each vendor has the same naming convention (all vendors are named by VENDOR### for example VENDOR001). However, the list of vendors can change at any point of time and either expand or shrink (this will result in a vendor list of VENDOR001 - VENDOR###). 

 

I was thinking of using an array because it will allow for the growing/shrinking of the vendor list. I was also thinking of using ranuni to randomly select an element of the array. For example:

data test; 
	array _Vendor{*} $6. VENDOR001-VENDOR005 ; 
	r = ceil(dim(_Vendor) * ranuni(12345)); 
	random_element = _Vendor{r}; 
run; 

/* --OR-- */ 

data test; 
	array _Vendor{*} $6. VENDOR001-VENDOR005 ; 
	r = ceil(dim(_Vendor) * ranuni(12345)); 
	random_element = _Vendor{r}; 
	rand_int = rand("Integer", 1, dim(_Vendor));
	value = _Vendor(rand_int);
run; 

However, I am struggling in implementing this method and I am curious if there is a more straight forward way. To clarify, I need to generate the vendor table and then join to the table I created from pulling data from oracle. 

 

Any insight would be much appreciated, if I left out any details that would be necessary to answer this question please let me know. 

 

Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your first method will work, but it's the same issue as before. You don't have a SET statement so no values are really assigned. 

And you're assigning the array value which you've never initialized, you did set the variable name though. You can either initialize the array or use the VNAME to get the variable name.

 

delete_random.JPG

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Your first method will work, but it's the same issue as before. You don't have a SET statement so no values are really assigned. 

And you're assigning the array value which you've never initialized, you did set the variable name though. You can either initialize the array or use the VNAME to get the variable name.

 

delete_random.JPG

 

lhsumdalum
Obsidian | Level 7
Reeza,

Thank you for going above and beyond to assist me with this question - incredibly helpful & much appreciated !

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!

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
  • 694 views
  • 0 likes
  • 2 in conversation