Does someone know how to replace a series of conditions as below :
if toto ne 0 then a = '1'; else a = '0';
if tutu ne 0 than b = '1'; else b = '0';
if titi ne 0 then c = '1'; else c = '0';
if tata ne 0 than d = '1'; else d = '0';
if tete ne 0 than e = '1'; else e = '0';
OK, so the statements are the same, only variables change.
Use arrays:
data have;
input toto tutu titi tata tete;
datalines;
1 1 0 1 0
;
data want;
set have;
array in {*} toto tutu titi tata tete;
array out {*} $ a b c d e;
do i = 1 to dim(in);
out{i} = ifc(in{i} ne 0,'1','0');
end;
drop i;
run;
The ifc() function is a simplification of your if/then/else.
OK, so the statements are the same, only variables change.
Use arrays:
data have;
input toto tutu titi tata tete;
datalines;
1 1 0 1 0
;
data want;
set have;
array in {*} toto tutu titi tata tete;
array out {*} $ a b c d e;
do i = 1 to dim(in);
out{i} = ifc(in{i} ne 0,'1','0');
end;
drop i;
run;
The ifc() function is a simplification of your if/then/else.
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.