全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1700 5
2013-09-18
创建两个宏变量 &startdate &enddate, 然后用这两个宏变量在macro里做do loop的起点和终点(见下边的代码),但是貌似"01JAN2000"d这种格式不能再macro里用,

%let startdate = 01JAN2000;%let enddate =  01JAN2004;

%macro date;
    %do j = "&startdate"d to "&enddate"d;
              ........;
    %end;
%mend;


程序报错:
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: "&startdate"d
ERROR: The %FROM value of the %DO J loop is invalid.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: "&enddate"d
ERROR: The %TO value of the %DO J loop is invalid.
ERROR: The macro AVG_INTEREST_COUNTRY will stop executing.


这个怎么破?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-9-18 13:59:32
宏变量的值是字符型的!
要进行计算的话,你加%eval();
%macro date;
    %do j =%eval(&startdate) to %eval(&enddate);
              ........;
    %end;
%mend;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-9-18 14:15:06
%let begindt= %sysfunc(inputn(01jan2013,date9.));
%put &begindt;
%let enddt= %sysfunc(inputn(02jan2013,date9.));
%put &enddt;

%macro test;
%do i= &begindt %to &enddt;
data a&i;
a=&i;
date=&i;
format date mmddyy10.;
run;
%end;
%mend test;
%test;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-9-18 23:43:22
妖帝东皇 发表于 2013-9-18 13:59
宏变量的值是字符型的!
要进行计算的话,你加%eval();
%macro date;
%eval()好像不行,“01Jan2000”d不是一个表达式

A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: "11MAR2002"d
ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.
ERROR: The %FROM value of the %DO J loop is invalid.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: "28JAN2013"d
ERROR: %EVAL function has no expression to evaluate, or %IF statement has no condition.
ERROR: The %TO value of the %DO J loop is invalid.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-9-18 23:53:21
tangliang0905 发表于 2013-9-18 14:15
%let begindt= %sysfunc(inputn(01jan2013,date9.));
%put &begindt;
%let enddt= %sysfunc(inputn(02jan ...
%sysfunc可以!多谢多谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-9-19 06:54:26
superyxo 发表于 2013-9-18 23:53
%sysfunc可以!多谢多谢!
哈哈!我也是昨天刚看见这个eval和sysfunc
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群