I have a data set that include several paths and the last variable is the frequency of the people following the path.
data path;
input path1 path2 path3 path4 path5 path6 frequency;
cards;
2 5 3 6 7 2 465
4 3 2 3 0 0 20394
2 1 3 6 5 0 309
1 3 2 6 5 3 302
2 2 5 4 7 7 6783
;
run;
I would like to calculate the frequency from the former stop to the latter stop along each path to count their individual frequency. since there are 7 stops. there will be 49 combinations, so I wrote a macro code.
%macro count(name,f,l);
data path;
set me.path;
retain &name;
&name=0;
%let i=0;
%do %until (&i=6);
%let i = %eval(&i+1);
%if path&i=&f and path&i=&l %then &name=%eval(&name+frequency);
%end;
run;
%mend;
%count(P2t5,2,5);
although the code itself presents no problem, the if condition always returns false no matter what I do. for example, I would expect in the first iteration of the do until loop, the if condition will be true, but it returns as false.
Something tells me it has to do with the path&i=&f
, is it not recognizing the path&i as a variable name or something else?
Can anyone solve this problem for me please?
Thanks!