以下是初始宏代码
list(map(set,df.values))
Out[72]: [{1, 2}, {2, 3}, {4, 5, 9}]
我想要做两件事。将sno中的值设置为no,如新的数据集 下方。
%let bdate='01JAN2001'd ;
%let bno=11;
%let date='01JAN2001'd ;
%let sno=%eval(&bno + %sysfunc(intck(month,&bdate,&date)));
%let no=%eval(&sno.+2)
%put &=date &=sno &=no;
DATE='01JAN2001'd SNO=11 no=13
其次我想根据上面解决的宏sno在proc SQL下面迭代到no,我的意思是按照上面的值,它必须是从11,12和13循环而不使用宏。
no
11
12
13
以下是使用上面解析的宏后迭代的proc SQL逻辑。
proc sql;
create table new &no as select from sample where deal in (&no);
quit;
我不想把上面的proc SQL放到宏和修补过程中。它必须继续。
proc SQL;
create table new11 as select from sample where deal in (11);
quit;
proc SQL;
create table new12 as select from sample where deal in (12);
quit;
proc SQL;
create table new13 as select from sample where deal in (13);
quit;
答案 0 :(得分:0)
没有宏的循环方式是使用call execute
。但是,在大多数情况下,使用宏将导致代码更容易编写和理解。如果由于某种原因你不得不远离宏,你可以完成你所描述的内容:
%let bdate='01JAN2001'd ;
%let bno=11;
%let date='01JAN2001'd ;
%let sno=%eval(&bno + %sysfunc(intck(month,&bdate,&date)));
%let no=%eval(&sno + 2);
%put &date &sno &no;
data sno_to_no;
do no = &sno to &no;
output;
end;
run;
data sample;
set sno_to_no;
deal = no;
run;
data _null_;
set sno_to_no;
call execute('proc sql; create table new'||strip(no)||' as select * from sample where deal in ('||strip(no)||'); quit;');
run;
根据您的需要,您可以通过在output
数据步骤中的sno_to_no
语句之前执行调用执行来简化操作。你显然不需要我在这里提供的sample
数据步骤 - 我包含它,所以代码将运行我的例子。