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;
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.