FILENAME statement is not executable, so they will happen while the data step is being compiled. So by the time your IF statement runs both FILENAME statements have already executed.
You can use the FILENAME() function instead.
Run this example to see that using the FILENAME() function makes the assignment conditional.
%let name=name_a;
%let path=%sysfunc(pathname(work));
data _null_;
if "&name" = "name_a" then do;
filename cd_file "&path/aa.js";
end;
else if "&name" = "name_b" then do;
filename cd_file "&path/bb.js";
end;
run;
%put CD_FILE -> %scan(%sysfunc(pathname(cd_file)),-1,\/);
data _null_;
if "&name" = "name_a" then do;
rc=filename('cd_file',"&path/aa.js");
end;
else if "&name" = "name_b" then do;
rc=filename('cd_file',"&path/bb.js");
end;
run;
%put CD_FILE -> %scan(%sysfunc(pathname(cd_file)),-1,\/);