Use the ARRAY statement to read in the numeric values to be changed. Use the existing numeric variable names as the element names of the array, or use the automatic variable _NUMERIC_ to process all existing numeric variables. Click the Full Code tab to see sample code that illustrates this.
Note: The ARRAY statement also provides the automatic variable _CHARACTER_ for processing character variables.
The MISSING function can also be used to detect missing values.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Example 1 - Convert all numeric missing values to zero. */
/* */
/* Use the ARRAY statement with the automatic _NUMERIC_ variable to */
/* process all the numeric variables from the input data set. Use */
/* the DIM function to set the upper bound of an iterative DO to the */
/* number of elements in the array. */
/* */
/* NOTE: The MISSING function can be used as well to test for */
/* character or numeric missing values. If you have */
/* mixed data types and want to use arrays, you'll need one */
/* array for the character variables, and another array for */
/* numeric variables. */
/* Create sample data */
data numbers;
input var1 var2 var3;
datalines;
7 1 4
. 0 8
9 9 .
5 6 2
8 3 0
;
data nomiss(drop=i);
set numbers;
array testmiss(*) _numeric_;
do i = 1 to dim(testmiss);
if testmiss(i)=. then testmiss(i)=0;
end;
run;
proc print;
run;
/* Example 2 -- Convert selected numeric values from zero to missing. */
/* */
/* Use the ARRAY statement to define the specific numeric variables to */
/* change from a value of zero to a missing value. Use the DIM function */
/* to set the upper bound of an iterative DO to the number of elements in */
/* the array. */
data deptnum;
input dept qtr1 qtr2 qtr3 qtr4;
datalines;
101 3 0 4 9
410 8 7 5 8
600 0 0 6 7
700 6 5 0 9
901 3 8 7 0
;
data nozero(drop=i);
set deptnum;
/* Note numeric variables DEPT and QTR4 will not be affected */
array testzero(*) qtr1-qtr3;
do i = 1 to dim(testzero);
if testzero(i)=0 then testzero(i)=.;
end;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Example 1 Obs var1 var2 var3 1 7 1 4 2 0 0 8 3 9 9 0 4 5 6 2 5 8 3 0 Example 2 Obs dept qtr1 qtr2 qtr3 qtr4 1 101 3 . 4 9 2 410 8 7 5 8 3 600 . . 6 7 4 700 6 5 . 9 5 901 3 8 7 0
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Data Management ==> Manipulation and Transformation ==> Array processing |
Date Modified: | 2006-12-23 03:02:57 |
Date Created: | 2004-09-30 14:09:05 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | All | n/a | n/a |