SAS Macro Do LOOP [英] SAS Macro Do LOOP
本文介绍了SAS Macro Do LOOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望偶数年有一个sas宏循环,因此do循环将从2006年跳到2008年到2010年……一直跳到2018年,而不是从2006年跳到2007年.
I want to have a sas macro loop by even years, so the do loop would jump from 2006 to 2008 to 2010...all the way to 2018 and not from 2006 to 2007.
当我执行%by = 2时,SAS无法正常工作,并显示一条错误消息.最好的解决方案是什么?
When I do a %by = 2, SAS doesn't work and gives me an error message. What is the best solution?
我有以下代码:
%macro import;
%do I = 2006 %to 2018;
data BTI&I;
set edited.Bti_&I;
year=&I;
run;
%end;
%mend import;
%import;
推荐答案
添加%by 2
关键字以增加间隔2.我还建议将开始和结束年份作为参数传递给您并给出默认值2006和2018.
Add the %by 2
keyword to increment intervals of 2. I would also recommend passing the start and end years as parameters to your function and give defaults values of 2006 and 2018.
%macro import(start=2006, end=2018);
%do I = &start. %to &end. %by 2;
data BTI&I;
set edited.Bti_&I;
year=&I;
run;
%end;
%mend import;
%import;
用法:
-
%import();
,它将使用默认值2006&2018 -
%import(start = 2009,end = 2018);
指定要使用的日期范围
%import();
which will use the default values 2006 & 2018%import(start=2009, end=2018);
specify the date range you want to use
这篇关于SAS Macro Do LOOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文