SAS中文论坛

标题: 请问,在proc sql中,可以执行类似于do的循环码? [打印本页]

作者: shiyiming    时间: 2009-9-28 10:56
标题: 请问,在proc sql中,可以执行类似于do的循环码?
[color=#FF00BF:1voo374j][size=150:1voo374j]请问,在proc sql中,可以执行类似于在data步中的do...to...end的循环码?

多谢指教![/size:1voo374j][/color:1voo374j]
作者: shiyiming    时间: 2009-9-28 12:40
标题: Re: 请问,在proc sql中,可以执行类似于do的循环码?
用CASE WHEN...THEN ... END语句,case 语句可以嵌套。
例如:
[code:2ywa20ji]data a;
a=1;
b=0;
output;
a=2;
b=.;
output;
run;
proc sql;
        create table b as
        select a.a, a.b,
                (CASE when b=. then
                        case when a=1 then 'a miss'
                                 when a=2 then 'miss'
                                else ''
                        end
                        when b=1 then '1'
                        else ''
                END) as test
        from a;
quit;[/code:2ywa20ji]
作者: shiyiming    时间: 2009-9-28 14:53
标题: Re: 请问,在proc sql中,可以执行类似于do的循环码?
[color=#BF00BF:1ubey8rv][size=150:1ubey8rv]不好意思啊,我想实行的功能是类似于:[/size:1ubey8rv][/color:1ubey8rv]
[code:1ubey8rv]
%macro test;

data a;
set b;
%do i=1 %to 5;
select;
when var_&i. = '1'  xvar='x1';
when var_&i. = '2'  xvar='x2';
when var_&i. = '10'  xvar='B';
when var_&i. = '11'  xvar='Z';
otherwise xvar=.;
end;
%end;
run;

%mend test;

%test;
[/code:1ubey8rv]
[size=150:1ubey8rv][color=#BF00BF:1ubey8rv]
希望可以在proc sql中实现,谢谢!

[/color:1ubey8rv][/size:1ubey8rv]




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2