楼主: flutter88
1424 5

[原创博文] 大家帮忙看看这段宏哪里有问题 [推广有奖]

  • 1关注
  • 1粉丝

已卖:1616份资源

教授

11%

还不是VIP/贵宾

-

威望
0
论坛币
5406 个
通用积分
0.1043
学术水平
7 点
热心指数
8 点
信用等级
1 点
经验
891 点
帖子
541
精华
0
在线时间
1629 小时
注册时间
2007-3-23
最后登录
2025-8-10

楼主
flutter88 发表于 2009-9-28 17:31:26 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
数据集new里面有5个变量V1 V2 V3 V4 V5,现在想计算每个变量中数值大于0的观测数。

我先将变量名V1 V2 V3 V4 V5分别赋给5个宏
macro1macro2macro3macro4macro5


然后通过下面的代码,把每个变量中数值大于0的观测数赋给宏变量
number1number2number3number4number5



%macro test;
%do i=1 %to 5;
proc sql noprint;
select count(*) into :number&i
from new
where &&macro&i>0;
quit;
%end;
%mend test;


上面的程序在运行时没有报错,但是运行完了以后number1到number5都解析不了!!!!


哪位大侠帮忙看看是什么问题呢?
二维码

扫码加我 拉你入群

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

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

关键词:哪里有 proc sql Number Select Macro

回帖推荐

xiaosanmao 发表于3楼  查看完整内容

data x; input v1-v5; cards; 0 1 2 3 4 -1 -3 4 5 -3 ; run; proc contents data=x out=y noprint; run; proc sql noprint; select distinct name into :names separated by ' ' from y order by names;quit; %macro test; %do i=1 %to 5; proc sql ; select count(*) into :names from x where v&i>0; quit; %put &names; %end; %mend; %test;

jingju11 发表于5楼  查看完整内容

1# flutter88 你是如何知道无法解析的? 就你的程序,如果在test之外解析,那不行,因为不是global的。但是,或者是用强制global再开个玩笑,你的advanced test是怎么过的?

本帖被以下文库推荐

沙发
flutter88 发表于 2009-9-28 17:36:00
但是下面这段程序是可以的:

%let i=1;
proc sql noprint;
select count(*) into :number&i
from new
where &&macro&i>0;
quit;


这时候number1是可以解析的!!!

好奇怪!
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

藤椅
xiaosanmao 发表于 2009-9-28 18:52:57
data x;
input v1-v5;
cards;
0  1  2  3 4
-1 -3 4 5 -3
;
run;
proc contents data=x
out=y noprint; run;
proc sql noprint;
select distinct name
     into :names separated by ' '
     from y order by names;quit;
  
%macro test;
%do i=1 %to 5;
proc sql ;
   select count(*) into :names
    from x where v&i>0;
    quit; %put &names;
%end;
%mend;
%test;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

板凳
flutter88 发表于 2009-9-28 22:16:25
哈哈,这样也可以。

报纸
jingju11 发表于 2009-9-28 22:27:00
1# flutter88

你是如何知道无法解析的?
就你的程序,如果在test之外解析,那不行,因为不是global的。但是,
  1. %macro test;
  2. %do i=1 %to 2;
  3.    proc sql noprint;
  4.       select count(*) into :number&i from new where &&macro&i>0;
  5.    quit;
  6. %end;
  7. %put &number1 &number2;
  8. %mend test;

  9. %test
  10. ;
复制代码
或者是用强制global
  1. %macro test;
  2. %global number1 number2;
  3. %do i=1 %to 2;
  4.    proc sql noprint;
  5.       select count(*) into :number&i from new where &&macro&i>0;
  6.    quit;
  7. %end;
  8. %mend test;

  9. %test
  10. ;
  11. %put &number1 &number2;
复制代码
再开个玩笑,你的advanced test是怎么过的?
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

地板
flutter88 发表于 2009-9-28 22:49:03
jingju11 发表于 2009-9-28 22:27
1# flutter88

你是如何知道无法解析的?
就你的程序,如果在test之外解析,那不行,因为不是global的。但是,
  1. %macro test;
  2. %do i=1 %to 2;
  3.    proc sql noprint;
  4.       select count(*) into :number&i from new where &¯o&i>0;
  5.    quit;
  6. %end;
  7. %put &number1 &number2;
  8. %mend test;

  9. %test
  10. ;
复制代码
或者是用强制global
  1. %macro test;
  2. %global number1 number2;
  3. %do i=1 %to 2;
  4.    proc sql noprint;
  5.       select count(*) into :number&i from new where &¯o&i>0;
  6.    quit;
  7. %end;
  8. %mend test;

  9. %test
  10. ;
  11. %put &number1 &number2;
复制代码
再开个玩笑,你的advanced test是怎么过的?
多谢,哈哈!

我没有过advanced啊。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 12:07