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

I have a dataset with 3000 records. One of the variables is blank for now,but we expect values in next refresh. How to add dummy values with no specific order and also the count of each value is not main concern.

for example variable_reqd  is blank in dataset "have" . But the variable need to have values  'a','b','c','d' in "want" for all 3000 rows.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
rand table is old, 9.2 or 9.1 I think so would work here.

View solution in original post

10 REPLIES 10
SASPhile
Quartz | Level 8

There is an ERROR reported:

ERROR: Attempt to initialize element of numeric array r with
character constant 'a'.

SASPhile
Quartz | Level 8

I tried that before reaching out. But still the below error is reported:

 

5553 array r{4} $ _temporary_ ('a','b','c','d');
5554 variable_reqd = r{rand('integer',1,4)};
5555 run;

ERROR: The first argument of the RAND function must be a
character string with a value of BERNOULLI, BETA,
BINOMIAL, CAUCHY, CHISQUARE, ERLANG, EXPONENTIAL, F,
GAMMA, GAUSSIAN, GEOMETRIC, HYPERGEOMETRIC, LOGNORMAL,
NEGB, NORMAL, POISSON, T, TABLE, TRIANGULAR, UNIFORM, or
WEIBULL.

Reeza
Super User
You're likely on a version of SAS that doesn't have the integer option for rand yet. What is your SAS version?

Rick Wicklin has a macro on his blog to replicate the function.
SASPhile
Quartz | Level 8

SAS version:9.04.01M3P062415

Reeza
Super User
array r{0:3} $ _temporary_ ('a','b','c','d');
variable_reqd = r(mod(_n_, 4);

If it doesn't matter where they go, just loop them.
ballardw
Super User

@Kurt_Bremser wrote:

Then you need to use the uniform distribution with a little additional work:

r{floor(rand('uniform')*4)+1}

 

Edit: changed normal to uniform


or r[rand('table',.25,.25,.25,.25)} might work.

 

I don't remember which version introduced the rand('table').

Reeza
Super User
rand table is old, 9.2 or 9.1 I think so would work here.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 1767 views
  • 3 likes
  • 4 in conversation