Create a variable based on the count of other variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Create a variable based on the count of other variables

Hi all, 

 

How can I create a new variable that is the count of other variables?

 

For example,

 

DATA TESTTEMP;
INFILE DATALINES TRUNCOVER;
INPUT ID DX1 DX2 DX3 DX4 DX5;
CARDS;
1 8 32 21 24 45
2 8 23 3 , ,
3 23 44 56 3
;
RUN;

PROC PRINT DATA=TESTTEMP;
RUN;

 

What I am expecting is the output dataset like this

 

ID     DX1     DX2     DX3     DX4     DX5      NDX
1         8          32       21         24        45         5
2         8           23       3                                   3
3        23          44      56          3                      4

 

Best,

 

Liang

 


Accepted Solutions
Solution
‎03-16-2018 01:50 PM
PROC Star
Posts: 1,833

Re: Create a variable based on the count of other variables

[ Edited ]
Posted in reply to Jackwangliang

All Replies
Solution
‎03-16-2018 01:50 PM
PROC Star
Posts: 1,833

Re: Create a variable based on the count of other variables

[ Edited ]
Posted in reply to Jackwangliang
ndx=n(of dx:);
Occasional Contributor
Posts: 17

Re: Create a variable based on the count of other variables

Posted in reply to novinosrin
Thank you. Smiley Happy
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 90 views
  • 0 likes
  • 2 in conversation