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.
data want;
set have;
array r{4} _temporary_ ('a','b','c','d');
variable_reqd = r{rand('integer',1,4)};
run;
There is an ERROR reported:
ERROR: Attempt to initialize element of numeric array r with
character constant 'a'.
My bad. Add a dollar sign to the array statement:
array r{4} $ _temporary_ ('a','b','c','d');
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.
SAS version:9.04.01M3P062415
Then you need to use the uniform distribution with a little additional work:
r{floor(rand('uniform')*4)+1}
Edit: changed normal to uniform
@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').
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!
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.