Macros 如何在sas宏数据步骤中使用周期
我需要在写入数据步骤的sas宏中使用周期 我有一个代码,应该可以工作,但它没有。我怎样才能修好它Macros 如何在sas宏数据步骤中使用周期,macros,sas,sas-macro,Macros,Sas,Sas Macro,我需要在写入数据步骤的sas宏中使用周期 我有一个代码,应该可以工作,但它没有。我怎样才能修好它 %macro ci; data %do i=1 %to 3; _z%sysfunc(putn(%eval(&i),z2.)) ; %end; ; set _06; %do i=1 %to 3; if num="%sysfunc(putn(%eval(&i),z2.))" then output _z%sysfunc(putn(%eval(&i),z2.)); %en
%macro ci;
data
%do i=1 %to 3;
_z%sysfunc(putn(%eval(&i),z2.)) ;
%end;
;
set _06;
%do i=1 %to 3;
if num="%sysfunc(putn(%eval(&i),z2.))" then output _z%sysfunc(putn(%eval(&i),z2.));
%end;
run;
%mend;
%ci;
我希望得到以下输出:
data
_z01
_z02
_z03;
set _06 ;
if num="01" then output _z01;
if num="02" then output _z02;
if num="03" then output _z03;
run;
如果使用更简单的方法而不是将数字转换为字符,怎么样
data _06;
num='01';
output;
num='02';
output;
num='03';
output;
run;
%macro ci;
data
%do i=1 %to 3;
_z0&i
%end;
;
set _06;
%do i=1 %to 3;
if num="0&i" then output _z0&i;
%end;
run;
%mend;
%ci;
你很接近。你只是有一个额外的
代码>在第一个循环中
您需要更改:
data
%do i=1 %to 3;
_z%sysfunc(putn(%eval(&i),z2.)) ;
%end;
;
致:
添加选项mprint代码>到代码的开头将显示从宏语句生成的代码,并帮助您调试它。我认为您不需要在那里使用%EVAL。
data
%do i=1 %to 3;
_z%sysfunc(putn(%eval(&i),z2.))
%end;
;