楼主: 爱萌
1625 6

请大家帮个忙,看看这个sas程序怎么保证正确,并提高一下 [推广有奖]

贵宾

已卖:262份资源

学术权威

54%

还不是VIP/贵宾

-

威望
8
论坛币
96603 个
通用积分
12.3686
学术水平
231 点
热心指数
299 点
信用等级
157 点
经验
102555 点
帖子
6174
精华
1
在线时间
2024 小时
注册时间
2007-3-2
最后登录
2025-12-1

楼主
爱萌 发表于 2012-6-29 13:16:56 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
%macro where_cond(size);
%let wherecond=;
%do i=1 %to &size-1;
        %do j=&i+1 %to &size;
         %let wherecond=&wherecond & &i.ordernumber=&j.ordernumber and &i.itemname<>&j.itemname;
%end;
%end;
%let wherecond=&wherecond;
%mend;
%where_cond(2);
%put &wherecond;
因为sql的条件太多了,我想通过宏实现,但是解析不了,估计是&符号有关
二维码

扫码加我 拉你入群

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

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

关键词:sas程序 Number Where Order Macro 程序

本帖被以下文库推荐

最恨对我说谎或欺骗我的人

沙发
爱萌 发表于 2012-6-29 13:17:46
测试结果如下:
1          %macro where_cond(size);
2          %let wherecond=;
3          %do i=1 %to &size-1;
4               %do j=&i+1 %to &size;
5                %let wherecond=&wherecond and &i.ordernumber=&j.ordernumber and &i.itemname<>&j.itemname;
6          %end;
7          %end;
8          %let wherecond=&wherecond;
9          %mend;
10         %where_cond(2);
11         %put &wherecond;
WARNING: Apparent symbolic reference WHERECOND not resolved.
&wherecond
NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           0.02 seconds
      cpu time            0.01 seconds
最恨对我说谎或欺骗我的人

藤椅
hopewell 发表于 2012-6-29 13:29:50
  1. %macro where_cond(size);
  2.      %global wherecond=;
  3. %mend;
复制代码
观钓颇逾垂钓趣 种花何问看花谁

板凳
爱萌 发表于 2012-6-29 13:40:58
hopewell 发表于 2012-6-29 13:29
谢谢,但是还有一些ERROR
1          %macro where_cond(size);
2          %global wherecond=;
3          %do i=1 %to &size-1;
4               %do j=&i+1 %to &size;
5               %if &i=1 and &j=2 %then %let wherecond=&i..ordernumber=&j..ordernumber & &i..itemname<>&j..itemname;
6               %else %let wherecond=&wherecond & &i..ordernumber=&j..ordernumber and &i..itemname<>&j..itemname;
7          %end;
8          %end;
9          %global wherecond=&wherecond;
10         %mend;
11         %where_cond(2);
ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name 1..
ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name 2..
ERROR: Invalid symbolic variable name &.
ERROR: Invalid symbolic variable name 1..
ERROR: Invalid symbolic variable name <>.
ERROR: Invalid symbolic variable name 2..
12         %put &wherecond;
1.ordernumber=2.ordernumber & 1.itemname<>2.itemname
最恨对我说谎或欺骗我的人

报纸
猫咪海盗船长 发表于 2012-6-29 14:30:39
不懂,帮你顶顶
hi!

地板
hopewell 发表于 2012-6-29 15:27:19
  1. %macro where_cond(size);
  2. %global wherecond;
  3. %do i=1 %to &size-1;
  4.     %do j=&i+1 %to &size;
  5.         %if &i=1 and &j=2 %then %let wherecond=&i..ordernumber=&j..ordernumber and &i..itemname<>&j..itemname;
  6.         %else %let wherecond=&wherecond and &i..ordernumber=&j..ordernumber and &i..itemname<>&j..itemname;
  7.     %end;
  8. %end;
  9. %mend;
  10. %where_cond(2);
  11. %put NOTE-&wherecond;
复制代码
观钓颇逾垂钓趣 种花何问看花谁

7
zhentao 发表于 2012-6-29 15:47:55
hopewell 发表于 2012-6-29 15:27
学习了,谢谢。
请教一下,爱萌的那个程序里的第一个%let定义的变量在这里不是和%global一个作用吗?
谢谢。

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

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