楼主: superyxo
1730 5

[问答] 在macro里用date的问题 [推广有奖]

  • 2关注
  • 1粉丝

硕士生

64%

还不是VIP/贵宾

-

威望
0
论坛币
91 个
通用积分
1.0005
学术水平
7 点
热心指数
2 点
信用等级
2 点
经验
9870 点
帖子
93
精华
0
在线时间
199 小时
注册时间
2007-8-28
最后登录
2021-4-15

楼主
superyxo 发表于 2013-9-18 13:07:47 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
创建两个宏变量 &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.


这个怎么破?

二维码

扫码加我 拉你入群

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

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

关键词:Macro date acr ATE Mac character function required ERROR where

沙发
妖帝东皇 发表于 2013-9-18 13:59:32
宏变量的值是字符型的!
要进行计算的话,你加%eval();
%macro date;
    %do j =%eval(&startdate) to %eval(&enddate);
              ........;
    %end;
%mend;

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
superyxo + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

┏━━━━━━━━━━━━━━┓
   ☞❤学而无友必然孤陋寡闻!❤
┗━━━━━━━━━━━━━━┛

藤椅
tangliang0905 发表于 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;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
superyxo + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

板凳
superyxo 发表于 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.

报纸
superyxo 发表于 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
┏━━━━━━━━━━━━━━┓
   ☞❤学而无友必然孤陋寡闻!❤
┗━━━━━━━━━━━━━━┛

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 09:26