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
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.
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.
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 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.