全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1089 5
2012-02-11
小弟在处理一些金融数据。假设我有数据集A,
date state
01      3
02      4
03      1
同时我还有程序步B,和C,
我该如何表达,才能使得当最小的state小于2时,我执行程序B,否则我就执行程序C。
二维码

扫码加我 拉你入群

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

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

全部回复
2012-2-11 20:17:42
U can use macro to realize it.

%macro choice(state);
%if &state. < 2 %then %do;
        程序B
%end;%else %do;
        程序C
%end;
%mend;

* example of 程序B ;
%choice(state = 1);

* example of 程序C ;
%choice(state = 4);
二维码

扫码加我 拉你入群

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

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

2012-2-12 17:28:02
maidenhan 发表于 2012-2-11 20:17
U can use macro to realize it.

%macro choice(state);
thank you

but what I want is to identify the least state value, then compare it with 2 to decide whether to run programB or C
二维码

扫码加我 拉你入群

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

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

2012-2-13 10:36:28
blliufan 发表于 2012-2-12 17:28
thank you

but what I want is to identify the least state value, then compare it with 2 to decid ...
用proc sort 对state 排序一下,然后对第一条观测值,即最小的state 用call symput 放入宏变量,再按maidenhan的建议写宏就可以了。
二维码

扫码加我 拉你入群

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

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

2012-2-13 14:32:39
zhangzachary 发表于 2012-2-13 10:36
用proc sort 对state 排序一下,然后对第一条观测值,即最小的state 用call symput 放入宏变量,再按maid ...
多谢多谢,我去试试,牛人。
二维码

扫码加我 拉你入群

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

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

2012-2-14 10:59:54
* example of 程序B ;
%choice(state = 1);

* example of 程序C ;
%choice(state = 4);

对于以上语句,建议楼主使用比较清晰指代的宏得名字:

%macro choice(state);
%if &state. < 2 %then %do;
        B(state)
        %end;
%else %do;
        C(state)
        %end;
%mend;

%macro B(state);
...;

%macro C(state);
...;
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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