KApril
KApril

Reputation: 700

Missing values not replaced SAS SQL

I am trying to replace missing values from D_Score numerical variable with 0. I dont get the values replaces and also no error. I am not sure what is the issue.

proc sql;
  create table Scores as
  select pa_id, 
        sum(D_I_score) as D_score, 
        sum(C_I_score) as C_score, 
        sum(R_I_score) as R_score, 
        sum(G_I_score) as G_score,  
            (case when  calculated D_score IS NULL then 0 else D_score end) as D_score

  from Join_G_ABS
  group by pa_id;
quit;

Upvotes: 0

Views: 454

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270843

You have two columns with the same name. I think you want:

select pa_id, 
       coalesce(sum(D_I_score), 0) as D_score, 
       sum(C_I_score) as C_score, 
       sum(R_I_score) as R_score, 
       sum(G_I_score) as G_score 

That is, do the definition "in place". Also, coalesce() is simpler than the case logic you are using.

Upvotes: 2

Related Questions