0

Dataset

This is the data set, what I want to do is to count how many Yes in each row, like the first row has 3 Yes so in my new column called Product_Held will have "3".

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Alvin
  • 1
  • 2

1 Answers1

0

In SQL, you can use:

proc sql;
    select t.*,
           ( (case when bank_account = 'Yes' then 1 else 0 end) +
             (case when credit_card = 'Yes' then 1 else 0 end) +
             . . . 
           ) as num_yeses
    from t;

You can create a view using:

proc sql;
    create view <viewname> as
        select t.*,
               ( (case when bank_account = 'Yes' then 1 else 0 end) +
                 (case when credit_card = 'Yes' then 1 else 0 end) +
                 . . . 
               ) as num_yeses
        from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • thank you for your answer, but is this able to update the table? or just to create view? If I would like to add a new column with this what can i do? – Alvin Aug 14 '21 at 11:25
  • @Alvin . . . This runs a query which produces a result set that has a new column with the value. That appears to be what your question is asking for. – Gordon Linoff Aug 14 '21 at 11:45
  • But how i can add the view column to my dataset? So sorry I am a new to programming – Alvin Aug 14 '21 at 13:25