楼主: rockfido
2876 4

[问答] 如何在同一个data step创建并使用macro variable [推广有奖]

  • 0关注
  • 0粉丝

已卖:1754份资源

博士生

32%

还不是VIP/贵宾

-

威望
0
论坛币
2715 个
通用积分
0.0341
学术水平
1 点
热心指数
1 点
信用等级
0 点
经验
4441 点
帖子
201
精华
0
在线时间
202 小时
注册时间
2008-8-29
最后登录
2024-11-1

楼主
rockfido 在职认证  发表于 2014-4-12 03:47:21 |AI写论文
100论坛币
请教:如何让下面的程序给出我想要的答案。
其实我就是想在一个data step中创建一个macro variable: testvar,但是还需要紧接着就可以用这个macro variable来创建一个新变量:a2。

我知道call symput创建的macro var必须先把当前data step关闭才可以调用,请问还有别的办法可以完成我的这个编程想法吗?

谢谢大家了!!

data test1;
input a b c;
cards;
1 1 1
;
run;

data test2;
set test1;
do i = 1 to 2;
a1 = i;
call symput('testvar',a1);  
%put &testvar.;
a2 = &testvar.;  *ALL I want is to get a2 = 1 for the first record and 2 for the second record in a dynamic way;
output;
end;
run;

最佳答案

bobguy 查看完整内容

You can use the resolve function in this case. a2 = resolve('&testvar');
关键词:Data step Variable Macro ABLE Step macro variable

沙发
bobguy 发表于 2014-4-12 03:47:22
You can use the resolve function in this case.

a2 = resolve('&testvar');

藤椅
farmman60 发表于 2014-4-12 05:10:46
change to:

a2=symget('testvar');

板凳
intheangel 学生认证  发表于 2014-4-14 15:13:53
我不知道理解的对不对,但是a1的值已经就是%upcase(&testvar.);
  1. data test1;
  2. input a b c;
  3. cards;
  4. 1 1 1
  5. ;
  6. run;
  7. %macro a;
  8. data test2;
  9. set test1;
  10. do i = 1 to 2;
  11. a1 = i;
  12. %let testvar=a1;
  13. a2=%upcase(&testvar.);
  14. output;
  15. end;
  16. run;
  17. %mend;
  18. %a
复制代码
我是一只瘦瘦的小猪~~~
╭︿︿︿╮
{/-◎◎-/}
( (oo) )
  ︶︶︶

报纸
crazygoing 发表于 2014-4-14 15:20:09
ALL I want is to get a2 = 1 for the first record and 2 for the second record in a dynamic way
你这个意思是不是就是想生成观测值序号,那就直接用a2=_N_;就行了。

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

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