data RandClass(drop=i);
call streaminit(1234);
set sashelp.cars(keep=Cylinders Horsepower Enginesize);
array x {*} _numeric_;
do i = 1 to dim(x);
if rand("Bern", 0.1) then /* p=0.4 ==> about 40% missing */
x[i]=.; end;
run;
proc print;
run;
data sashelp;
set sashelp.cars;
update cars Randclass;
by Cylinders Horsepower Enginesize;
run;
proc print cars;
I have removed data values randomly from three variables cylinders horsepower and enginesize from sashelp.cars. when i am trying to update newly created varaibles with missing value in data set sashelp.cars its giving me errors like
The error is clear, do you have a dataset CARS created, check your library? If not then check your code. I think you meant to create a dataset called CARS but you called it SASHELP instead? Make sure you're consistent with the names used.
Your code won't work for a number of reasons. For one you select every cell, as the random number will always be greater than 0, thus the condition will always be true.
Second, you never create the file cars but, rather, a file called sashelp
Art, CEO, AnalystFinder.com
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.