Arrays in SAS!!

                                           SAS arrays are a collection of elements (usually SAS variables) that allow you to write SAS statements referencing this group of variables. SAS arrays are different from arrays in many other programming languages. They do not hold values, and they convenient manner. In this post we can see some problem based on arrays.

#Problem:

                Using the SAS data set Nines, create a SAS data set, where all values of 999 are replaced by SAS missing values. Do this without explicitly naming the numeric variables in data set Nines.

#Data set:


data A15028.A28_nines;
   infile datalines missover;
   input x y z (Char1-Char3)(:$1.) a1-a5;
datalines;
1 2 3 a b c 99 88 77 66 55
2 999 999 d c e 999 7 999
10 20 999 b b b 999 999 999 33 44
;
proc print data=A15028.A28_nines; run;

#Solution:   


data A15028.A28_nines1;
set A15028.A28_nines;
array nums{*} _numeric_;
do i = 1 to dim(nums);
if nums{i} = 999 then
call missing(nums{i});
end;
drop i;
run;
proc print data=A15028.A28_nines1;
run;

#Output:





#Learning :

                             In this program we get the idea about array and how it works in SAS. We used the do loop and dim function. Here we called missing value wherever 999 is present in the data set. 

             

No comments:

Post a Comment