BookmarkSubscribeRSS Feed
chintanpatel
Calcite | Level 5

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
   x[i]=.;  /* p=0.4 ==> about 40% missing */
   end;
run;

 

Hello everyone, this is my code to delete values from columns randomly. It is working completely fine.

In the code 0.1 decides the percentage to delete. if i write there 0.2 it will delete 20% of the values and so on. I want to run a loop there that it will select values from 0.1 to 0.4 by 0.05. so total it should do 7 times. and I want to store all this 7 databases for future use. can anyone help me to do it ?

1 REPLY 1
Reeza
Super User

Here's one way. Another is to use a macro loop to generate the data you need.

 

data RandClass;
	call streaminit(1234);
	set sashelp.cars(keep= Cylinders Horsepower EngineSize obs=50);
	array x {*} _numeric_;

	do p=0.1 to 0.5 by 0.1;
		do i = 1 to dim(x);
			if rand("Bern", p) then
				x[i]=.;
		end;

		output;
	end;
run;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 620 views
  • 0 likes
  • 2 in conversation