楼主: lam_fukming
1277 7

[原创博文] A question about data computation in SAS [推广有奖]

  • 3关注
  • 9粉丝

已卖:1921份资源

博士生

20%

还不是VIP/贵宾

-

威望
0
论坛币
6005 个
通用积分
12.2090
学术水平
43 点
热心指数
43 点
信用等级
40 点
经验
94521 点
帖子
324
精华
0
在线时间
25 小时
注册时间
2011-8-29
最后登录
2025-5-7

楼主
lam_fukming 发表于 2012-8-5 19:18:53 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
For example, I have a data taking the values as follows. How can I assign each value of t as t(1), t(2), ... , and x as x(1), x(2), ... so that I can compute something likes ln[x(2)/x(1)], ln[x(3)/x(2)], ... , and name these values as a new variable y.Don't tell me to do it in Excel. Of course, I know how to do this simply in Excel, but I just want to know whether it can be perform in SAS so that I do not need to switch from Excel and SAS so frequently.


data a;
input t x;
cards;
1 10
2 13
3 17
4 14
5 16
6 18
7 15
8 12
9 11
10 15
;
run;
二维码

扫码加我 拉你入群

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

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

关键词:Computation question Comput Quest About something question example whether course

沙发
lam_fukming 发表于 2012-8-7 08:54:55
怎麼没人理我?
大道無門,
千差有路,
透得此關,
乾坤獨步﹗

藤椅
hcydlee 发表于 2012-8-7 09:10:09
如果你需要的结果仅是相邻两数相除的自然对数的话,可以用下面的程序。当然如果不是相邻的,但是间隔是由规律的,也可以,比如lag(x)换成lag2(x)就是隔一个数相除。
data b;
        set a;
        lagx=lag(x);
        y=log(x/lagx);
        if _N_ ne 1 then output;
run;
80 字节以内
不支持自定义 Discuz! 代码

板凳
maidenhan 发表于 2012-8-7 09:19:05
U can use array or proc IML to deal with your problem.
Sorry, I don't how to use IML, so just illustrate an example by array.

data b(keep = array_ans compare_ams);
        array at{10} _temporary_;
        array ax{10} _temporary_;
        retain at ax;
        do i = 1 to 10;
                set a point=i;
                at{i} = t;
                ax{i} = x;
        end;
        array_ans = ax{3} / ax{2};
        compare_ams= 17/13;
        output;
        stop;
run;

报纸
lam_fukming 发表于 2012-8-8 20:17:48
maidenhan 发表于 2012-8-7 09:19
U can use array or proc IML to deal with your problem.
Sorry, I don't how to use IML, so just illu ...
Thanks, I understand your logic. Then, I do something like "ax(j+1)/ax(j)", but why no result is shown?
大道無門,
千差有路,
透得此關,
乾坤獨步﹗

地板
maidenhan 发表于 2012-8-9 09:15:01
lam_fukming 发表于 2012-8-8 20:17
Thanks, I understand your logic. Then, I do something like "ax(j+1)/ax(j)", but why no result is s ...
Show us your code, or we don't know what goes wrong.

7
lam_fukming 发表于 2012-8-9 22:39:50
maidenhan 发表于 2012-8-9 09:15
Show us your code, or we don't know what goes wrong.
I input the following:

data a;                                                                                                                                 
input t x;                                                                                                                              
cards;                                                                                                                                 
1 10                                                                                                                                    
2 13                                                                                                                                    
3 17                                                                                                                                    
4 14                                                                                                                                    
5 16                                                                                                                                    
6 18                                                                                                                                    
7 15                                                                                                                                    
8 12                                                                                                                                    
9 11                                                                                                                                    
10 15                                                                                                                                   
;                                                                                                                                       
run;                                                                                                                                    
data b;                                                                                                                                 
array ax{10};                                                                                                               
        do i = 1 to 10;                                                                                                                 
                set a point=i;                                                                                                         
                ax{i} = x;                                                                                                              
        output;                                                                                                                        
        end;                                                                                                                           
run;                                                                                                                                    
data c;                                                                                                                                 
        do j = 2 to 10;                                                                                                                 
        set b;                                                                                                                          
        r = ax{j+1} / ax{j};                                                                                                   
        output;                                                                                                                        
        end;                                                                                                                           
run;                                                                                                                                    
proc print data=c;                                                                                       
var r;                  
run;                                                                                                                                    
大道無門,
千差有路,
透得此關,
乾坤獨步﹗

8
maidenhan 发表于 2012-8-10 08:35:34
lam_fukming 发表于 2012-8-9 22:39
I input the following:

data a;                                                                  ...
1, U have to add a "stop;" sentence in the end of "data b" code.
2, U have set "i = 2 to 10", but computer couldn't understand what ax{i+1} means when i = 10.

U can find my advice below.

data c;
        array ax{10};
        do i = 1 to 10;                                                                                                                 
                set a point=i;                                                                                                         
                ax{i} = x;                                                                                                                                                                                                                                 
        end;
        do j = 1 to 9;   
                r = ax{j+1} / ax{j};
                output;
        end;
        stop;
run;

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

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