全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1142 2
2016-12-13
各位老师好:
请问能否将这2个sql合并成1个?
谢谢!

或者:
同个data步中上面生成变量下面可以直接调用,
sql中是否不能直接调用?

proc sql;
    create table card1 as
        select *,
            int(addcode/1000000) as procode,
            int(rearea/1000000) as citycode,
            year(dateotype) as bgyear,
            input(compress(card_id,"‘’"),$40.) as cardid,
            input(compress(ic,"‘’"),$18.) as ic_
         
        from card
        where areatype not in ("港澳台" "外籍") and
            flagoval eq "已终审卡"                and
            typeocase in ("实验室诊断病例" "临床诊断病例") and
            dateotype between '01jul1985'd and '30jun2014'd ;

quit;

proc sql;
    create table card2 as
    select *
    from card1
    where procode eq 44;
quit;


***上面2个sql生成的结果与data步生成的一样;
data card1;
    set card;
procode=int(addcode/1000000);
citycode=int(addcode/10000);   *addcode=现住址;
reptcode=int(rearea/1000000);  *rearea=报告地;
cityrept=int(rearea/10000);

bgyear=year(dateotype);  

cardid=input(compress(card_Id,"‘’"), $40.);
    ic_=input(compress(ic,"‘’"), $18.);

if areatype='港澳台' or areatype='外籍' then delete;
if (flagoval='已终审卡' and (typeocase='实验室诊断病例' or typeocase='临床诊断病例')) and procode=44;

if '01jul1985'd<=dateotype<='30jun2014'd;    *dateotype=录入日期;  *有7例的录入日期是20140701;

run;


二维码

扫码加我 拉你入群

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

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

全部回复
2016-12-13 16:09:24
data card1;
    set card(where=(areatype not in ("港澳台" "外籍") and
            flagoval eq "已终审卡"                and
            typeocase in ("实验室诊断病例" "临床诊断病例") and
            dateotype between '01jul1985'd and '30jun2014'd));

procode=int(addcode/1000000);
citycode=int(addcode/10000);   *addcode=现住址;
reptcode=int(rearea/1000000);  *rearea=报告地;
cityrept=int(rearea/10000);
bgyear=year(dateotype);  
cardid=input(compress(card_Id,"‘’"), $40.);
ic_=input(compress(ic,"‘’"), $18.);


if procode=44;


run;
************************************************************************
************************************************************************
************************************************************************
proc sql;
    create table card1 as
        select *,
            int(addcode/1000000) as procode,
            int(rearea/1000000) as citycode,
            year(dateotype) as bgyear,
            input(compress(card_id,"‘’"),$40.) as cardid,
            input(compress(ic,"‘’"),$18.) as ic_
         
        from card
        where areatype not in ("港澳台" "外籍") and
            flagoval eq "已终审卡"                and
            typeocase in ("实验室诊断病例" "临床诊断病例") and
            dateotype between '01jul1985'd and '30jun2014'd  and int(addcode/1000000)=44;

quit;
************************************************************************
************************************************************************
二维码

扫码加我 拉你入群

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

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

2016-12-13 16:24:23
lovexialulu 发表于 2016-12-13 16:09
data card1;
    set card(where=(areatype not in ("港澳台" "外籍") and
            flagoval eq "已终 ...
好。
谢谢!

看来同个sql中下面的where不能调用上面生成的变量。
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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