The program is: %macro loop(testcd=);
data data2;
set data;
if %scan(&testcd.,1) eq 1 %if %length(&testcd.) gt %length(%scan(&testcd.,1)) %then %do; and %scan(&testcd.,2) eq 1 %end; then do;
value=1;
end;
else if %scan(&testcd.,1) eq 0 %if %length(&testcd.) gt %length(%scan(&testcd.,1)) %then %do; and %scan(&testcd.,2) eq 0 %end; then do;
value=0;
end;
run;
%mend;
%loop(testcd=%str(Indx55)); %macro loop2(testcd=); data aa; set data; a=%scan(&testcd.,1); b=%length(%scan(&testcd.,1)); run; %mend; %loop2(testcd=%str(Indx55)); The program creates a new column VALUE, my question is that what does the if loop mean? I only know the form like if xx then do; xxx; end; or %if xx %then %do; xxx; %end; But it is if xx %if xx %then %do; and xxx %end; then do; end; which seems abnormal in syntax. But it did run successfully. Does anyone know how to understand this program ? The data and the data2 in the above program are like this, data - AVISIT INDX55 Week2 0 Week4 0 Week8 1 Week12 1 ... data2 - Another question is that why %scan(&testcd.,1)=the value of Indx55, while %length(%scan(&testcd.,1))=6? (see %loop2 above)
... View more