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);

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3767 views
  • 7 likes
  • 3 in conversation