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

Dear members,

 

I am doing a simulation in SAS. I generated (1000 cases and 53 variables). 53 variables include Id and 52 vars: i1 to 140 is either 0 or 1, i41 to i52 is either 1, 2 or 3.  The data looks like below.

 

ID     i1 to i52

0001 0010001000110100111111111001100101010000113211313133
0002 0111000011011001010011001011001100000100131111211112
0003 0010010001101100110111100011110110000101111111123122
0004 1111111111111111111011111111111111111101333322333332
0005 1111111111111111110111110011111101111101333312333332
0006 0111000000011001101101101011000110100100133121311121

.

.

 

I want to randomly select 4 vars from 52 vars and replace the values with blank. This needs to done for the first 20 cases (out of 1000). The randomly selected 4 vars are different for each case.  (need loop here)

 

How to randomly select 4 variables? And how should I conditionally process variables to replace the values with missing?

 

 

 

 

Thanks so much!

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ah, I missed that. Then it is actually a lot simpler:

 

data have(drop=j);
   format ID;
   array i{52};
   do ID=1 to 1000;
      do j=1 to dim(i);
         i[j]=floor(4*rand('uniform'));
      end;
      output;
   end;
   format ID z4.;
run;

data want;
   set have;
   array iVars i1-i52;
   array idx idx1-idx48;
   if _N_<=20 then do until (cmiss(of iVars[*])=48);
      call missing(iVars[ceil(52*rand('uniform'))]);
   end;
   drop idx:;
run;

This should resolve both issue (1) and (2)..

 

Let me know if this works for you? 🙂

View solution in original post

8 REPLIES 8
PGStats
Opal | Level 21

Put your variables in an array, then

 

Select a random index

if the array element is not missing, set it to missing
repeat until you have set 4 values to missing.

PG
TX_STAR
Obsidian | Level 7

Hi PG,

Thanks.

I was able to generate random index and put it in macro variable and use it in arrays as below.

Now I want to do loop for the first 20 cases (such as do _n_=1 to 20) so that each case have a different set of 48 randomly selected variable with missing and 4 without (in the original question, the number of variables with missing is 4, without is 48. Sorry for the confusion). 

 

How can I put the following code together to loop for the first 20 cases (out of 1000)?

 

 

--------------------------------------- sas code---------------------------------------------------------------------------------------------------------------
data _null_;
call streaminit(1234);
run;

 

proc sql /*noprint */;
create table all_vars as
select name
from sashelp.vcolumn /*DICTIONARY.COLUMNS*/
where libname = 'WORK' AND memname = 'MATH' AND NAME not in ( 'ID' 'bucket')
order by rand('uniform')
;
quit;

 

ata nomiss miss;
set all_vars;
if _n_ le 4
then output nomiss;
Else output miss;
run;

 


proc sql noprint;
select name into :mvarlist separated by ' ' from miss;
select name into :nmvarlist separated by ' ' from nomiss;
quit;
%put "list of variables with missing:&mvarlist.";
%put "list of variables without missing:&nmvarlist.";

 


data math_w_miss;
set math;
if bucket = 0 then do;
array miss [48] &mvarlist.;
array nmiss [4] &nmvarlist.;
do m=1 to 48;
miss{m}=.;
end;
do n=1 to 4;
nmiss{n}=nmiss{n};
end;
end;
run;

 

 

PeterClemmensen
Tourmaline | Level 20

A bit smoother than my first approach

 

data have(drop=j);
   format ID;
   array i{52};
   do ID=1 to 1000;
      do j=1 to dim(i);
         i[j]=floor(4*rand('uniform'));
      end;
      output;
   end;
   format ID z4.;
run;

data want;
   set have;
   array iVars i1-i52;
   array idx idx1-idx4;
   if _N_=1 then do over idx;
      idx=ceil(52*rand('uniform'));
   end;
   if _N_<=20 then do;
      call missing(iVars[idx1], iVars[idx2],iVars[idx3],iVars[idx4]);
   end;
   retain idx:;
   drop idx:;
run;
PeterClemmensen
Tourmaline | Level 20

There is definitely a smoother way, but using brute force, you can do something like this

 

data have(drop=j);
   format ID;
   array i{52};
   do ID=1 to 1000;
      do j=1 to dim(i);
         i[j]=floor(4*rand('uniform'));
      end;
      output;
   end;
   format ID z4.;
run;

data want;
   set have;
   array iVars i1-i52;
   if _N_=1 then do;
      idx1=ceil(52*rand('uniform'));
      idx2=ceil(52*rand('uniform'));
      idx3=ceil(52*rand('uniform'));
      idx4=ceil(52*rand('uniform'));
   end;
   if _N_<=20 then do;
      call missing(iVars[idx1], iVars[idx2],iVars[idx3],iVars[idx4]);
   end;
   retain idx:;
   drop idx:;
run;
TX_STAR
Obsidian | Level 7

Hi Draycut,

 

I modified your code and got what close to what I need. but I have two issues:

(1) I want 48 of 52 items have missing. however, my array..idx[j] did not work. I did it manually. The code looks like below. Is there a way to do array for idx so that the coding is easier?

 

(2) the idx1 to idx48 using the code below (idx1=ceil(52*rand('uniform'));) are not unique. How to add seed there so that the 48 idx are unique?

The generated data looks like below. there should be 48 blanks for each person. but due to duplicated idx, the number of blanks is <48.

 

Thanks,

 

 

 

 

 /*-------------------------------------- sas code----------------------------------------------------------------*/

data want;
set have;
array iVars i1-i52;

if _N_<=20 then do;

idx1=ceil(52*rand('uniform'));
idx2=ceil(52*rand('uniform'));
idx3=ceil(52*rand('uniform'));
idx4=ceil(52*rand('uniform'));
.

.

.
idx45=ceil(52*rand('uniform'));
idx46=ceil(52*rand('uniform'));
idx47=ceil(52*rand('uniform'));
idx48=ceil(52*rand('uniform'));


call missing(iVars[idx1],iVars[idx2],iVars[idx3],iVars[idx4],........,iVars[idx45],iVars[idx46],iVars[idx47],iVars[idx48]);
end;
retain idx:;
drop idx:;
run;

 

SAS Output

Obs ID i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 i21 i22 i23 i24 i25 i26 i27 i28 i29 i30 i31 i32 i33 i34 i35 i36 i37 i38 i39 i40 i41 i42 i43 i44 i45 i46 i47 i48 i49 i50 i51 i52
1 0001 0   2       0       0   2       0   2 1     2   1       2   1     3 3 3   2   3           2   3     2  
2 0002 1 3     2   1           0   2       2 0 2         0 0 2     2   0 2           2   2       2 0 0 3 3    
3 0003 2 3   0 0                   0 3     2 3           1   1 0 2 1           1     0   1     2 2 1   0 2    
4 0004 0 0 3 3 2 2       1       2   0 0 2     2   2       2       0 2             2     3   0           2    
5 0005   0     1   2         1     2     0   1   0 2     0 1 2   2     3       2 2       0     0   0 1   3    
6 0006   1       1   0 2   0   3         3 1   1             3 3   1 2 0 2 3 0 1 3 1 0       2         0 2    
7 0007 3       0         3   1   0         0         0 2 3     3 2 2     1   1   3   0 0       3 3         3 0
8 0008     0     0   3     1 1     3   1 3 0 1 0 2   2   1   1   0     0 1 0             2   1       3   2 1  
9 0009     0 3   1       0   2   3   2   0     3   3         1     3     2 2           2 3   3   3 2 1       1
10 0010 1 0 2       0 3   0                       0     1 1                 0       1   3   2 1 2   1   0     0
11 0011   1       1 2   2   1       0 0           0   2   2 2 1         2     0 2     1     2 1 0   2 1        
12 0012     2   2     3 1   3     3         2     2       3 0     0   1 3   0 3           0   3     0       2  
13 0013   3           0 1 0   0 3             2   1   0       3         3   3 0     0   0 1 0       1       0 3
14 0014   3 3   0 3   1     2 1   0   3   1 2 2 2   3       3           1 0 1     0           3           3 0  
15 0015   3   3     0 0 0   2           0 3   0   3           3       3 0 0   2 0   1         3   2   0   3    
16 0016           0       3   2 0   2   1 3 3 1   1   0     1 0   2                 3     3         1   3   3 3
17 0017         3     0       2     2     2           2 1       3 1 2 2   0   3   2       3   3   0 2   3 1    
18 0018           2                 0     2 1 3   2 2     0   2       3 0   0 0 3         3     0 2 0 1 3 2   3
19 0019 1 3     1     1       2   3   3 0           3 0 0 3     2           3 2 2   1       2 2         3 2 2  
20 0020 0 1   2   0           2 2       0         3     2           3         1 2     1             1     3   3
21 0021 2 0 0 1 1 2 3 0 0 2 2 1 2 2 0 2 2 3 0 3 3 2 0 1 3 3 2 2 1 3 3 3 1 0 3 3 3 0 1 3 2 0 0 3 1 2 0 2 1 1 2 3
22 0022 1 0 2 3 3 2 1 2 1 1 2 3 0 1 3 2 0 2 0 3 1 1 0 1 3 1 1 2 1 1 3 1 1 0 3 1 0 1 1 3 3 3 1 2 0 0 3 0 1 0 3 2
23 0023 1 0 2 1 3 0 0 3 1 0 2 0 3 1 2 0 1 1 3 0 3 2 0 1 0 0 1 1 1 2 0 2 3 3 3 3 1 3 1 2 2 2 0 2 3 2 0 3 0 0 1 2
24 0024 2 0 0 0 0 0 2 1 1 0 0 1 0 2 0 1 3 0 2 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 3 1 2 1 1 0 3 0 1 0 3 0 3 0 0 0 2 2 3 2 2 0 0 1
100 0100 1 1 3 3 0 1 2 3 1 3 3 2 3 3 2 1 0 0 3 0 3 0 3 1 1 0 1 1 1 1 2 2 3 0 1 3 0 1 2 0 1 3 2 3 0 3 2 3 3 2 0 1
PeterClemmensen
Tourmaline | Level 20

Ah, I missed that. Then it is actually a lot simpler:

 

data have(drop=j);
   format ID;
   array i{52};
   do ID=1 to 1000;
      do j=1 to dim(i);
         i[j]=floor(4*rand('uniform'));
      end;
      output;
   end;
   format ID z4.;
run;

data want;
   set have;
   array iVars i1-i52;
   array idx idx1-idx48;
   if _N_<=20 then do until (cmiss(of iVars[*])=48);
      call missing(iVars[ceil(52*rand('uniform'))]);
   end;
   drop idx:;
run;

This should resolve both issue (1) and (2)..

 

Let me know if this works for you? 🙂

TX_STAR
Obsidian | Level 7

Hi draycut,

 

It works perfect!

 

Thanks so much!

PeterClemmensen
Tourmaline | Level 20

Anytime. Glad to hear that it solved your problem 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 948 views
  • 0 likes
  • 3 in conversation