Hello,
I have a range of numeric variables (txn_a, txn_b, txn_c...) in my dataset that I need to recode missing to zero depending each other's response. The condition is that if any variables in this range is NOT missng the others variables missing should be recoded to zero.
Any ideas how can I can accomplish that with an array?
Thanks!
Use a flag to assign an existing missing value in the array,
then, according to flag value, replace missing by zero:
array name txn_a ... ;
flag=0;
do i=1 to dim(name);
if name(i)=. then do;
do while (i le dim(name));
flag=1;
if name(i) = . then name(i) = 0;
i+1;
end;
if flag=1 then leave;
end;
drop flag;
Use a flag to assign an existing missing value in the array,
then, according to flag value, replace missing by zero:
array name txn_a ... ;
flag=0;
do i=1 to dim(name);
if name(i)=. then do;
do while (i le dim(name));
flag=1;
if name(i) = . then name(i) = 0;
i+1;
end;
if flag=1 then leave;
end;
drop flag;
I keep getting the following error:
2754 run;
-
117
ERROR 117-185: There was 1 unclosed DO block.
NOTE: The SAS System stopped processing this step because of errors.
Here is my code:
data gls.txrecoded;
set gls.secondarytasp;
array name (9) txsnum_k12 txsnum_hed txsnum_sab txsnum_jj txsnum_er txsnum_tstg txsnum_cw txsnum_mh txsnum_phc;
flag=0;
do i=1 to dim(name);
if name(i)=. then do;
do while (i le dim(name));
flag=1;
if name(i) = . then name(i) = 0;
i+1;
end;
if flag=1 then leave;
end;
drop flag;
run;
Any ideas?
Since you have three DO statements and only two END statements the error message is pretty clear.
From your requirements you just need to do something like this.
data gls.txrecoded;
set gls.secondarytasp;
array name txsnum_k12 txsnum_hed txsnum_sab txsnum_jj txsnum_er txsnum_tstg txsnum_cw txsnum_mh txsnum_phc;
if n(of name(*)) then do i=1 to dim(name);
name(i)=sum(0,name(i));
end;
drop i;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.