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

I love SAS for it's arrays. I use it often to make imputations like this:  (change missing to the value 75)

 

data want; set have;
   array change [*] x1-x999;
            do over change;
            	if change=. then change=75;
            end;
run;

But what if, instead of changing to 75, I wanted impute to the minimum value of x. 

 

Thinking about this hurts my brain because I know that array is moving "sideways" and I'm looking for a whole dataset aggregation to obtain the minimum. 

 

I'm sure I could hack someting together, but I'm really worried about effiecency due to my dataset size.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I'm assuming your thinking of going column by column? Or is it min across all X, across all observations? 

 

You should take a look at Proc stdize with missing and replace options. 

View solution in original post

3 REPLIES 3
KachiM
Rhodochrosite | Level 12

Why not?

 

We can use the MINIMUM function with array.

 

Since DO OVER is deprecated, I use the usual way.

 

Here is the code.

data have;
input x1 x2 x3 x4 x5;
datalines;
10 12 11  3 10
 3  7 10  .  5
14  . 20  1  3
;
run;


data want;
   set have;
   array change[*] x1-x5;
   do i = 1 to dim(change);
      min = min(of change[*]);
      if change[i] = . then change[i] = min;
   end;
keep x:;
run;
Reeza
Super User

I'm assuming your thinking of going column by column? Or is it min across all X, across all observations? 

 

You should take a look at Proc stdize with missing and replace options. 

PGStats
Opal | Level 21

It can be done in a single data step:

 

data test;
set sashelp.class;
if age = 13 then call missing(height, weight);
run;

data testi;
if 0 then set test;
array _x {*} _numeric_;
array _m {9999} _temporary_;
do while(not endmin);
    set test end=endmin;
    do i = 1 to dim(_x);
        _m{i} = min(_m{i}, _x{i});
        end;
    end;
do while(not endimp);
    set test end=endimp;
    do i = 1 to dim(_x);
        if missing(_x{i}) then _x{i} = _m{i};
        end;
    output;
    end;
drop i;
stop;
run;
    
PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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