SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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