楼主: lnlhckao123
3620 25

[问答] 200论坛币求请问怎样在特定位置插入一个变量 [推广有奖]

21
majunzhen 发表于 2013-5-6 23:18:21
用data step 两步实现
第一步 把要加的变量 作为 最后一个变量 加到原来data set 里面。。
第二步 新的data step 一开始马上重新定义一下变量顺序。然后再把第一步的data set 读进来

22
yuerqieqie 发表于 2013-5-7 20:39:09
wodematlab 发表于 2013-5-3 23:22
用retain
这个是真理。
data bbb;
    if 0 then set aaa(keep = a--d)
    retain p;
    set aaa;
run;
   

23
yongyitian 发表于 2013-5-8 00:31:03
LZ 想 用sas sql;


data aaa;
ID = _N_;
input a b c d e f g h;
cards;
1 2 3 4 5 6 7 8
;

proc sql;
    create table bbb(drop=id)  as
    select a.*,  (a.a + b.e) as sum_ae, b.*
    from aaa (drop=e--h) as a, aaa(drop=a--d) as b
    where a.id=b.id;
quit;

或者
data ccc;
input a b c d e f g h;
cards;
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
;
proc sql noprint;
      select name into: a_e  separated by ', '
             from dictionary.columns
            where libname='WORK' and memname='CCC' and varnum in (1 2 3 4);
     select name into: e_h  separated by ', '
           from dictionary.columns
           where libname='WORK' and memname='CCC' and varnum in (5 6 7 8);
quit;
proc sql;
   select &a_e, sum(d) as sum_d, &e_h
   from ccc;
quit;

或者用 SQL 和 data step
proc sql noprint;
     select name into: a__e  separated by ' '
        from dictionary.columns
        where libname='WORK' and memname='CCC' and varnum in (1 2 3 4);
     select name into: e__h  separated by ' '
         from dictionary.columns
         where libname='WORK' and memname='CCC' and varnum in (5 6 7 8);
quit;

data ddd;
     retain &a__e sum_de &e__h;
     set ccc;
     sum_de = d+e;
run;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
lnlhckao123 + 5 + 3 + 3 热心帮助其他会员

总评分: 学术水平 + 5  热心指数 + 3  信用等级 + 3   查看全部评分

24
lnlhckao123 发表于 2013-5-11 21:14:45
谢谢各位高手!谢谢imasasor,虽然imassor的程序很好,但是imasasor没考虑到a   b  c   d   e  f   g    h只是随机顺序,也有可能是a   bb  cc   d   e  ff   gg    h,这时imasasor程序就用不了,但是这时farmman60的程序就可以用。故我将他的答案设为最佳答案!不过还是谢谢各位高手指导!!
即使在人大经济论坛这个网络世界,我仍以真诚为基础与我的好友进行交往!

25
lnlhckao123 发表于 2013-5-11 21:33:13
谢谢yongyitian!您在23楼的程序很精彩,但是小弟我学识有限,需要慢慢研究才能懂,要是您愿意,我愿意再设一个类似的帖子,您把23楼的答案粘帖进去,我将设它为最佳答案,再次谢谢各位高手精彩的回答!!
即使在人大经济论坛这个网络世界,我仍以真诚为基础与我的好友进行交往!

26
lnlhckao123 发表于 2013-5-12 23:06:20
您好farmman60!请问,上述程序中,P所代表的是数值型数据,怎样可以设定它为字符型变量,谢谢指点!!
即使在人大经济论坛这个网络世界,我仍以真诚为基础与我的好友进行交往!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 01:13