我构建了以下宏,其中代码遍历数字 1 到 82,并proc format
在创建该宏变量时分配语句中定义的格式:
%macro metric_var;
/*macro to define 86 metric variables using proc format statement. this only needs doing once. to save processing time*/
/*this macro is outside of the main macro loop and the proc format statement is outside the do loop within the macro*/
/*as again it only needs defining once.*/
proc format;
value metricvar
1 = a 2 = y 3 = b 4 = d 5 = b2
6 = r1 7 = b3 8 = q 9 = p 10 = o
11 = c1 12 = d1 13 = c 14 = d2
15 = c6 16 = t1 17 = k2 18 = p2
19 = c8 20 = m5 21 = c3 22 = m6
23 = g 24 = m7 25 = h 26 = m8
27 = k1 28 = m3 29 = l 30 = m4
31 = l1 32 = t8
33 = w1 34 = g1 35 = w4 36 = g3
37 = p1 38 = g4 39 = m 40 = g5
41 = m2 42 = g6
43 = k 44 = v 45 = j 46 = j1
47 = j5 48 = j3 49 = k4 50 = f6
51 = j6 52 = n 53 = k5 54 = n4
55 = w 56 = s 57 = s1 58 = x
59 = j2
60 = v 61 = a5 62 = b6 63 = k3
64 = t7 65 = a2 66 = t6 67 = i5
68 = l2 69 = e 70 = e7 71 = e8
72 = e9 73 = b4 74 = j4 75 = p5
76 = p6 77 = r 78 = r2 79 = r5
80 = r6 81 = r7 82 = s7
/*don't forget now runs to 86 metrics*/
;
run;
%let metvar1 = 1;
%let metvar2 = 82;
%do U = &metvar1. %to &metvar2. %by 1;
data _null_;
a = &u.;
call symput('myvar',(put(a,metricvar.)));
run;
%let myvar_&u. = &myvar.;
%put &myvar.;
%put &myvar_&u.;
%end;
%mend;
%metric_var;
在这种情况下,宏变量&myvar.
可以正常工作,并按照我的意愿按升序分配值。
然而,这个变量被赋予了一个新值 82 次,并且在过程结束时它具有最后一次迭代的值。
我试图用这条线做的%let myvar_&u. = &myvar.;
是然后创建 82 个单独的全局变量,这些变量将被调用&myvar_1.
,&myvar_82.
每个变量都有不同的值。
当日志运行时出现以下警告
WARNING: Apparent symbolic reference MYVAR_ not resolved.
&myvar_79
看来最后一个变量,我想要的那个没有被正确分配,我不知道为什么。
有人对问题所在有任何建议吗?
谢谢