Hello,
I would like to add a prefix text, 'SEC_', to the ARRAY variable columns as my code shown below. I got an error message from the log window. Please help me to fix it. Thanks.
data Want; set Have; array vars uairway uapnea ugastro ugerd uendo uallergy uprem unone; do over vars; if find(SEC_uothersp_update1,vname(vars),"i") then 'SEC_'||vars=1; end; run;
Log massage shows:
do over vars;
if find(SEC_uothersp_update1,vname(vars),"i") then 'SEC_'||vars=1;
------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
end;
Hi @ybz12003 Array variables are created at compile time and not at execution time. Therefore, your idea wouldn't work. However you could create another array statement defining its variable with SEC prefix like the below-
data Want;
set Have;
array vars uairway uapnea ugastro ugerd uendo uallergy uprem unone;
array s sec_uairway sec_uapnea sec_ugerd sec_uendo sec_uallergy sec_uprem sec_unone;
do over vars;
if find(SEC_uothersp_update1,vname(vars),"i") then s=1;
end;
run;
Hi @ybz12003 Array variables are created at compile time and not at execution time. Therefore, your idea wouldn't work. However you could create another array statement defining its variable with SEC prefix like the below-
data Want;
set Have;
array vars uairway uapnea ugastro ugerd uendo uallergy uprem unone;
array s sec_uairway sec_uapnea sec_ugerd sec_uendo sec_uallergy sec_uprem sec_unone;
do over vars;
if find(SEC_uothersp_update1,vname(vars),"i") then s=1;
end;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.