Sample 24675: Determine the maximum number of consecutive missing values per observation
Use arrays to store the number of missing values and
the MAX function to determine the maximum number
of 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.
/* Create sample data */
data mydata;
input id x1 x2 x3 x4 x5;
datalines;
1 2 . . . .
2 2 1 2 1 .
3 . 1 . 1 .
4 1 . . . 1
5 . . . 1 .
;
/* Create an array to hold the variables in the data set and another */
/* array called HOLD for the values of COUNT. If the value of a */
/* variable is missing, COUNT is incremented by one. If a variable's */
/* value is not missing, COUNT is placed into the array HOLD. */
/* When all variables are read, the maximum value of the HOLD */
/* array is computed and stored in HIGHCNT. */
data mydata2;
set mydata;
array test(5) x1-x5;
array hold(5);
count=0;
do i=1 to 5;
if test(i) =. then count+1;
if test(i) ne . or i=5 then do;
hold(i)=count;
count=0;
end;
end;
highcnt=max(of hold1-hold5);
drop i count;
run;
proc print noobs;
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.
id x1 x2 x3 x4 x5 hold1 hold2 hold3 hold4 hold5 highcnt
1 2 . . . . 0 . . . 4 4
2 2 1 2 1 . 0 0 0 0 1 1
3 . 1 . 1 . . 1 . 1 1 1
4 1 . . . 1 0 . . . 3 3
5 . . . 1 . . . . 3 1 3
Use arrays to store the number of missing values and
the MAX function to determine the maximum number
of missing values.
| Type: | Sample |
| Topic: | Data Management ==> Manipulation and Transformation ==> Array processing Common Programming Tasks ==> Utilities SAS Reference ==> DATA Step
|
| Date Modified: | 2005-12-08 11:34:19 |
| Date Created: | 2004-09-30 14:09:03 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |