楼主: zghnpdszkx
3675 3

[有偿编程] SAS能重复执行data 或 proc过程吗? [推广有奖]

  • 0关注
  • 0粉丝

初中生

4%

还不是VIP/贵宾

-

威望
0
论坛币
742 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
55 点
帖子
7
精华
0
在线时间
12 小时
注册时间
2009-8-21
最后登录
2020-4-5

楼主
zghnpdszkx 发表于 2015-11-10 12:08:18 |AI写论文
100论坛币
大家好,本人是SAS小白一枚,目前项目必须用SAS。
我现在有一个很大的数据集,里面每个观测包含3个变量,分别是tag,time, 和lying。每个tag下每天有24个时间值,对应24个lying值。目标是做每个tag下每个时间内lying值的线性回归。假设我有100个tag,则要做100*24次线性回归。
这是一个双重循环的问题,我知道怎么选出每个tag下每个time的值,并对其回归,但是不会循环这个过程。而且回归的结果输出在一result窗口里,能不能像matlab那样,将这些回归结果输出的到变量里,然后统一输出到一个excel文件里?以下是我目前的代码,一次只能处理一个tag,然后手动改tag值,再运行代码。能不能自动识别tag值,然后逐个对这些tag进行回归?由于不会循环,所以用的最笨办手动循环的方法,请不要嘲笑我。。。

再重复下我的目标,1自动识别tag值,并自动对每个tag值的24个时间段的值进行回归。2 将回归结果按tag 和时间段输出到excel文件中。
如果有人能实在上述功能,请联系我,可付报酬。论坛币,或者别的什么币都可以。

数据: data.zip (8.23 KB) 本附件包括:
  • data.csv
代码:
proc import datafile="Z:/nicky/data.csv" out=mydata dbms=csv replace;
    getnames=no;
run;

proc contents data=mydata;
run;



Data Cowtag;
Set Mydata;
If VAR1 = 1332 then output;
Run;



Data Cowlying0 Cowlying1 Cowlying2 Cowlying3 Cowlying4 Cowlying5 Cowlying6 Cowlying7 Cowlying8 Cowlying9 Cowlying10 Cowlying11 Cowlying12 Cowlying13 Cowlying14  Cowlying15 Cowlying16 Cowlying17 Cowlying18 Cowlying19 Cowlying20 Cowlying21 Cowlying22 Cowlying23;
Set Cowtag;

        If VAR3 = "0:00:00" then output Cowlying0;
        If VAR3 = "1:00:00" then output Cowlying1;        
        If VAR3 = "2:00:00" then output Cowlying2;
        If VAR3 = "3:00:00" then output Cowlying3;        
        If VAR3 = "4:00:00" then output Cowlying4;
        If VAR3 = "5:00:00" then output Cowlying5;        
        If VAR3 = "6:00:00" then output Cowlying6;
        If VAR3 = "7:00:00" then output Cowlying7;        
        If VAR3 = "8:00:00" then output Cowlying8;
        If VAR3 = "9:00:00" then output Cowlying9;        
        If VAR3 = "10:00:00" then output Cowlying10;
        If VAR3 = "11:00:00" then output Cowlying11;        
        If VAR3 = "12:00:00" then output Cowlying12;
        If VAR3 = "13:00:00" then output Cowlying13;
        If VAR3 = "14:00:00" then output Cowlying14;
        If VAR3 = "15:00:00" then output Cowlying15;        
        If VAR3 = "16:00:00" then output Cowlying16;
        If VAR3 = "17:00:00" then output Cowlying17;        
        If VAR3 = "18:00:00" then output Cowlying18;
        If VAR3 = "19:00:00" then output Cowlying19;        
        If VAR3 = "20:00:00" then output Cowlying20;
        If VAR3 = "21:00:00" then output Cowlying21;        
        If VAR3 = "22:00:00" then output Cowlying22;
        If VAR3 = "23:00:00" then output Cowlying23;        

Run;


Data Cowlying0;
Set Cowlying0;

h=substr(VAR6,1,1);
m=substr(VAR6,3,2);
y0=h*60+m;
x0=_n_;

Run;

proc reg;
model y0=x0;
run;

Data Cowlying1;
Set Cowlying1;

h=substr(VAR6,1,1);
m=substr(VAR6,3,2);
y1=h*60+m;
x1=_n_;

Run;

proc reg;
model y1=x1;
run;

Data Cowlying2;
Set Cowlying2;

h=substr(VAR6,1,1);
m=substr(VAR6,3,2);
y2=h*60+m;
x2=_n_;

Run;

proc reg;
model y2=x2;
run;

Data Cowlying3;
Set Cowlying3;

h=substr(VAR6,1,1);
m=substr(VAR6,3,2);
y3=h*60+m;
x3=_n_;

Run;

proc reg;
model y3=x3;
run;

…… 一直重复到cowlying23

最佳答案

johnpark1 查看完整内容

你不需要分开做, 用BY就可以了。 Proc sort data=yourdata; by byVariable; Proc reg data=yourdata outest=outest; By byVariable;Model y=x; Run; 这样一次就相当于把做所有by variable value分别做回归。
关键词:Data ROC contents replace Content matlab result excel 而且 项目

沙发
johnpark1 发表于 2015-11-10 12:08:19
你不需要分开做, 用BY就可以了。
Proc sort data=yourdata; by byVariable;
Proc reg data=yourdata outest=outest;
By byVariable;Model y=x;
Run;


这样一次就相当于把做所有by variable value分别做回归。
已有 1 人评分论坛币 热心指数 信用等级 收起 理由
admin_kefu + 20 + 4 + 2 热心帮助其他会员

总评分: 论坛币 + 20  热心指数 + 4  信用等级 + 2   查看全部评分

藤椅
zghnpdszkx 发表于 2015-11-10 22:25:29
johnpark1 发表于 2015-11-10 12:24
你不需要分开做, 用BY就可以了。
Proc sort data=yourdata; by byVariable;
Proc reg data=yourdata out ...
谢谢你的方法,精简了大量重复代码。但是我这个是双重循环,现在外层还有一次数据选取要手动设参数,这个能做成自动循环吗?

现在我的代码如下:
proc import datafile="Z:/nicky/data.csv" out=mydata dbms=csv replace;
    getnames=no;
run;

proc contents data=mydata;
run;

Data mydata;
Set mydata;

h=substr(VAR6,1,1);
m=substr(VAR6,3,2);
y=h*60+m;
x=_n_;
Run;

Data Cowtag;
Set Mydata;
If VAR1 = 1332 then output; /*这里tag值有很多个,需要一个一个手动修改,如何做成自动?*/
Run;

Proc sort data=Cowtag; by VAR3;
Proc reg data=Cowtag outest=outest;
By VAR3;Model y=x;
Run;

板凳
johnpark1 发表于 2015-11-11 13:08:44
By 变量可以是多维的。你这里好像是二维。试一下以下程序:


Proc sort data=mydata; by Var1 var3;
Proc reg data=mydata outest=outest;
By var1 VAR3;
Model y=x;
Run;

如果成功的话,不要忘记发赏金

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

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