全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2847 4
2014-04-12
悬赏 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');
二维码

扫码加我 拉你入群

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

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

全部回复
2014-4-12 03:47:22
You can use the resolve function in this case.

a2 = resolve('&testvar');
二维码

扫码加我 拉你入群

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

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

2014-4-12 05:10:46
change to:

a2=symget('testvar');
二维码

扫码加我 拉你入群

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

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

2014-4-14 15:13:53
我不知道理解的对不对,但是a1的值已经就是%upcase(&testvar.);
复制代码
二维码

扫码加我 拉你入群

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

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

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_;就行了。
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群