🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-27-2019 07:25 AM
(3522 views)
Hello
I want to create a new calculated field that will count number of fields(from fields x1-x6) that are not null.
For Id=1 I expect to get value 6
For Id=2 I expect to get value 6
For Id=3 I expect to get value 4
What is the way to do it please without change the dimension of the table(without transpose)
data tbl;
input ID x1 x2 x3 x4 x5 x6 ;
cards;
1 9 8 7 6 7 8
2 7 7 6 7 7 8
3 7 7 6 7 . .
;
run;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The function nmiss returns the number of missing values, you just need to subtract the total number of vars.
data want;
set tbl;
array values x1-x6;
NotMissing = dim(values) - nmiss(of x1-x6);
run;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The function nmiss returns the number of missing values, you just need to subtract the total number of vars.
data want;
set tbl;
array values x1-x6;
NotMissing = dim(values) - nmiss(of x1-x6);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why not use NotMissing = n(of x1-x6);