楼主: Tigflanker
2972 5

求助一个宏变量引入的数值类型不匹配问题 [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

威望
0
论坛币
2321 个
通用积分
9.9128
学术水平
179 点
热心指数
194 点
信用等级
167 点
经验
27443 点
帖子
622
精华
0
在线时间
851 小时
注册时间
2011-3-27
最后登录
2023-5-14

楼主
Tigflanker 发表于 2013-2-24 20:41:51 |AI写论文
100论坛币
首先祝进来的朋友元宵节快乐!!

想问坛友一个细节的问题,如下:

  1. %macro abc(rm,tm);

  2. %let rm=%str(1.2,1,2,3,4,5,4);
  3. %let tm=%substr(&tm,2,%length(&tm)-2);

  4. %put &rm;   *这两个变量put出来显示是一样的;
  5. %put &tm;

  6. %do i=1 %to 5;
  7.   %let rv&i=%scan(&rm,&i,',');
  8.   %let tv&i=%scan(&tm,&i,',');   *报错;

  9.   %put rv&i tv&i;
  10. %end;
  11. %mend;

  12. %abc("3,2.8,2.6,2.4,2.2,2.0,1.8","3,2.7,2.4,2.1,1.8,1.5,1.2");
复制代码

我原意是想从宏变量引入带有逗号的数值串,但是scan不识别,请问该怎么修改呢?谢谢。

最佳答案

Imasasor 查看完整内容

%macro abc(rm,tm); %let rm=%bquote(1.2,1,2,3,4,5,4); %let tm=%substr(&tm,2,%length(&tm)-2); %put &rm; *这两个变量put出来显示是一样的; %put &tm; %do i=1 %to 5; %let rv&i=%scan(&rm,&i,%str(,)); %let tv&i=%scan(%bquote(&tm),&i,%str(,)); *报错; %put &&rv&i &&tv&i; %end; %mend; %abc(%bquote(3,2.8,2.6,2.4,2.2,2.0,1.8),%bquote(3,2.7,2.4,2.1,1.8,1.5,1.2)); 你宏中的 ...
关键词:不匹配 SUBSTR length Macro scan 元宵节
Bye SAS.
若有缘,能重聚。

沙发
Imasasor 发表于 2013-2-24 20:41:52
%macro abc(rm,tm);

%let rm=%bquote(1.2,1,2,3,4,5,4);
%let tm=%substr(&tm,2,%length(&tm)-2);

%put &rm;   *这两个变量put出来显示是一样的;
%put &tm;

%do i=1 %to 5;
  %let rv&i=%scan(&rm,&i,%str(,));
  %let tv&i=%scan(%bquote(&tm),&i,%str(,));   *报错;

  %put &&rv&i &&tv&i;
%end;
%mend;

%abc(%bquote(3,2.8,2.6,2.4,2.2,2.0,1.8),%bquote(3,2.7,2.4,2.1,1.8,1.5,1.2));


你宏中的参数rm是没有用的,你在宏中直接重新定义其值了
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

藤椅
Tigflanker 发表于 2013-2-24 20:59:35
%macro abc(rm,tm);

%let rm=%str(1.2,1,2,3,4,5,4);
%let tm=%substr(&tm,2,%length(&tm)-2);

data aa;
rm=symget('rm');
call symput('rm',rm);   *①如果把rm放入data步中洗一下;
run;

%put &rm;   *这两个变量put出来显示是一样的;
%put &tm;

%do i=1 %to 5;
  %let rv&i=%scan(&rm,&i,',');   *②这时rm也报错了,若没有上面的data步,则这步不报错;
  %let tv&i=%scan(&tm,&i,',');   *报错;
  %put &&rv&i &&tv&i;
%end;

%mend;

%abc("3,2.8,2.6,2.4,2.2,2.0,1.8","3,2.7,2.4,2.1,1.8,1.5,1.2");
Bye SAS.
若有缘,能重聚。

板凳
bobguy 发表于 2013-2-24 22:40:56
There is no variable type in SAS macro language. All of them is 'text'.

If you can formulate the problem as what do you have and what do you want + your sas code, it will help others to understand the problem better, and to offer better solutions.
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 已回复。

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

报纸
Tigflanker 发表于 2013-2-24 23:11:36
bobguy 发表于 2013-2-24 22:40
There is no variable type in SAS macro language. All of them is 'text'.

If you can formulate the ...
bob老师元宵节快乐,您说的很对,我忽略宏变量的本意了;

我这样只是想方便模拟时在整个宏的下方调用时控制组间的均数情况。
Bye SAS.
若有缘,能重聚。

地板
Tigflanker 发表于 2013-2-24 23:16:09
Imasasor 发表于 2013-2-24 22:45
%macro abc(rm,tm);

%let rm=%bquote(1.2,1,2,3,4,5,4);
是的,怪我没有阐述明白,本来想用tm这条路实现rm和tm两个组,但是发现行不通,我就按原来的方法把rm的路截断了。

您的方法很有启示,谢谢。顺祝版主元宵快乐。
Bye SAS.
若有缘,能重聚。

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

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