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

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
andreas_lds
Jade | Level 19

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;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

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;
Ksharp
Super User
Why not use NotMissing = n(of x1-x6);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3646 views
  • 7 likes
  • 3 in conversation