DATA Step, Macro, Functions and more

I want to create a new variable and see if the entire row has 0 or any value

Reply
Contributor
Posts: 63

I want to create a new variable and see if the entire row has 0 or any value

course        class          user             score            post     forum      quiz             assign     main         group  

1001200130010100000
1001200230010000000
1001200130010000000
1001200230015000000

In this example if we see the third and fourth column has all zeros. i want to know which row has all zeros and which has atleast one value.

Any help please

Super User
Posts: 5,260

Re: I want to create a new variable and see if the entire column has 0 or any value

sql: select max(score)...?

Data never sleeps
Contributor
Posts: 63

Re: I want to create a new variable and see if the entire column has 0 or any value

Sorry for the confusion it is row and not column

Super User
Posts: 5,260

Re: I want to create a new variable and see if the entire column has 0 or any value

sum(score, post...)

Data never sleeps
Super Contributor
Posts: 333

Re: I want to create a new variable and see if the entire row has 0 or any value

Here is a simple flagging in a dataset. If you just want a dataset of the ids you could just keep those variables.

data out;

     set in;

     flag = 1 + sum(score, post, forum, quiz, assign, main, group);

     if flag = 1 then output;

run;

If you want to just produce a report you could use sql;

Proc sql;

     select course,   class,  user

               (1 +    score +  post  +   forum  +  quiz + assign  +   main + group ) as flag

     from in

     where calculated flag = 1

     ;

quit;

Just some thoughts, hope it helps!

EJ

PROC Star
Posts: 1,567

Re: I want to create a new variable and see if the entire row has 0 or any value

FOUND_VALUE_FLAG=sum(of SCORE--GROUP) ne 0;

provided the values can only be positive.

Otherwise something like

FOUND_VALUE_FLAG=lengthn(compress(cats(of SCORE--GROUP),'0.')) ne 0;

will take care of any real number.

Ask a Question
Discussion stats
  • 5 replies
  • 208 views
  • 0 likes
  • 4 in conversation