楼主: priss111
965 2

请问能否将这2个sql合并成1个?谢谢! [推广有奖]

  • 0关注
  • 5粉丝

副教授

15%

还不是VIP/贵宾

-

威望
0
论坛币
153 个
通用积分
47.5396
学术水平
11 点
热心指数
14 点
信用等级
10 点
经验
14938 点
帖子
473
精华
0
在线时间
805 小时
注册时间
2008-3-30
最后登录
2024-4-12

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
各位老师好:
请问能否将这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;


二维码

扫码加我 拉你入群

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

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

关键词:sql compress proc sql Between Create

沙发
lovexialulu 发表于 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;
************************************************************************
************************************************************************

使用道具

藤椅
priss111 发表于 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不能调用上面生成的变量。

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-19 21:25