楼主: yugao1986
1975 9

[原创博文] 数据合并疑问 [推广有奖]

教授

21%

还不是VIP/贵宾

-

威望
0
论坛币
53 个
通用积分
15.9206
学术水平
63 点
热心指数
83 点
信用等级
44 点
经验
30427 点
帖子
501
精华
0
在线时间
1977 小时
注册时间
2010-3-26
最后登录
2023-11-29

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
现有100只股票数据,命名形如:daysh600000,daysh600004...,daysz000001....,600000等是股票代码(id);数据的结构都一样,内含变量,date,open,high,close等,但不含股票代码:
data daysh600000;
input date open hight low clsoe;
cards;
2011 29.5 29.8 27 27.75
;
run;

现在想请教,如何合并这些数据,新数据中包含股票代码?新的数据格式:
id date open high low close
600000 2011 29.5 29.8 27 27.75
600000 .... .... ... ... ....
600004 2011 7.72 8.56 7.69 8.25
...
敬请高手指点迷津。
二维码

扫码加我 拉你入群

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

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

关键词:数据合并 Close cards Input days 股票代码 close 2011 命名 如何

沙发
black小猪 发表于 2012-6-12 13:22:46 |只看作者 |坛友微信交流群
spss 数据合并?

使用道具

藤椅
yugao1986 发表于 2012-6-12 16:01:30 |只看作者 |坛友微信交流群
black小猪 发表于 2012-6-12 13:22
spss 数据合并?
sas里面
三人行必有我师

使用道具

板凳
webgu 发表于 2012-6-12 16:19:58 |只看作者 |坛友微信交流群
yugao1986 发表于 2012-6-12 16:01
sas里面
小鱼,你试试这个。思路:从DICTIONARY里取DATASET 名,生成宏。然后截取dataset 名,并分别添加 id变量,最后APPEND.
  1. /* bulid test data set*/
  2. data daysh600000;
  3. input date open hight low clsoe;
  4. cards;
  5. 2011 29.5 29.8 27 27.75
  6. ;
  7. run;

  8. data daysh600001;
  9. input date open hight low clsoe;
  10. cards;
  11. 2012 29.5 29.8 27 27.75
  12. ;
  13. run;


  14. /*macro for appending data set*/
  15. options  symbolgen mprint mlogic;


  16. %macro app(inlib);
  17. proc sql;
  18.   select  distinct memname  into : dslist separated by " "
  19.   from sashelp.vcolumn
  20.   where libname=%upcase(&inlib);  /*change it to ("&inlib") */
  21. quit;

  22. %let dslist=&dslist;

  23.    %let i=1;
  24.    %do %while(%scan(&dslist,&i) ne );
  25.       %let ds=%scan(&dslist,&i);
  26.        data &ds;
  27.             id="&ds";
  28.                 set  &ds;
  29.         run;

  30.         proc append base=all  data=&ds  force;
  31.         run;
  32.         %let i=%eval(&i+1);
  33.         %put  %scan(&dslist,&i);
  34.         %end;
  35. %mend app;

  36. /*test*/
  37. %app(WORK);
复制代码
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

报纸
可~乐 发表于 2012-6-12 23:20:30 |只看作者 |坛友微信交流群
想问下这个100只股票数据不是批量导进来的么?
如果是批量导进来的,就可以直接获取数据集的名字了,然后再进行赋值,再合并就可以了,当然跟webgu大神的思路也是差不多一样的。。。

使用道具

地板
yugao1986 发表于 2012-6-13 15:38:49 |只看作者 |坛友微信交流群
webgu 发表于 2012-6-12 16:19
小鱼,你试试这个。思路:从DICTIONARY里取DATASET 名,生成宏。然后截取dataset 名,并分别添加 id变量, ...
谢谢webgu兄,不过我这里提示报错:
最近在折腾这些,折腾A股,2000多条
三人行必有我师

使用道具

7
webgu 发表于 2012-6-13 16:04:45 |只看作者 |坛友微信交流群
yugao1986 发表于 2012-6-13 15:38
谢谢webgu兄,不过我这里提示报错:
最近在折腾这些,折腾A股,2000多条
  1. /* bulid test data set*/
  2. data daysh600000;
  3. input date open hight low clsoe;
  4. cards;
  5. 2011 29.5 29.8 27 27.75
  6. ;
  7. run;

  8. data daysh600001;
  9. input date open hight low clsoe;
  10. cards;
  11. 2012 29.5 29.8 27 27.75
  12. ;
  13. run;


  14. /*macro for appending data set*/
  15. options  symbolgen mprint mlogic;



  16. %macro app(inlib);
  17. proc sql;
  18.   select  distinct memname  into : dslist separated by " "
  19.   from sashelp.vcolumn
  20.   where libname=%upcase("&inlib");
  21. quit;

  22.   %let i=1;
  23.    %do %while(%scan(&dslist,&i) ne );
  24.       %let ds=%scan(&dslist,&i);
  25.        data &ds;
  26.             id="&ds";
  27.                 set  &ds;
  28.         run;

  29.         proc append base=all  data=&ds  force;
  30.         run;
  31.         %let i=%eval(&i+1);
  32.         %put  %scan(&dslist,&i);
  33.         %end;
  34. %mend app;

  35. /*test: cation,do it only once*/
  36. %app(WORK);
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
yugao1986 + 1 + 1 + 1 分析的有道理

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

SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

8
webgu 发表于 2012-6-13 16:05:36 |只看作者 |坛友微信交流群
yugao1986 发表于 2012-6-13 15:38
谢谢webgu兄,不过我这里提示报错:
最近在折腾这些,折腾A股,2000多条
宏里面差了个引号。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

9
webgu 发表于 2012-6-13 16:06:11 |只看作者 |坛友微信交流群
%app(WORK);
MLOGIC(APP):  Beginning execution.
MLOGIC(APP):  Parameter INLIB has value WORK
MPRINT(APP):   proc sql;
SYMBOLGEN:  Macro variable INLIB resolves to WORK
MPRINT(APP):   select distinct memname into : dslist separated by " " from sashelp.vcolumn where
libname="WORK";
MPRINT(APP):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds


MLOGIC(APP):  %LET (variable name is DSLIST)
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
MLOGIC(APP):  %LET (variable name is I)
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 1
MLOGIC(APP):  %DO %WHILE(%scan(&dslist,&i) ne) loop beginning; condition is TRUE.
MLOGIC(APP):  %LET (variable name is DS)
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  Macro variable DS resolves to DAYSH600000
MPRINT(APP):   data DAYSH600000;
SYMBOLGEN:  Macro variable DS resolves to DAYSH600000
MPRINT(APP):   id="DAYSH600000";
SYMBOLGEN:  Macro variable DS resolves to DAYSH600000
MPRINT(APP):   set DAYSH600000;
MPRINT(APP):   run;

NOTE: There were 1 observations read from the data set WORK.DAYSH600000.
NOTE: The data set WORK.DAYSH600000 has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


SYMBOLGEN:  Macro variable DS resolves to DAYSH600000
MPRINT(APP):   proc append base=all data=DAYSH600000 force;
MPRINT(APP):   run;

NOTE: Appending WORK.DAYSH600000 to WORK.ALL.
NOTE: BASE data set does not exist. DATA file is being copied to BASE file.
NOTE: There were 1 observations read from the data set WORK.DAYSH600000.
NOTE: The data set WORK.ALL has 1 observations and 6 variables.
NOTE: PROCEDURE APPEND used (Total process time):
      real time           0.17 seconds
      cpu time            0.03 seconds


MLOGIC(APP):  %LET (variable name is I)
SYMBOLGEN:  Macro variable I resolves to 1
MLOGIC(APP):  %PUT %scan(&dslist,&i)
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 2
DAYSH600001
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 2
MLOGIC(APP):  %DO %WHILE(%scan(&dslist,&i) ne) condition is TRUE; loop will iterate again.
MLOGIC(APP):  %LET (variable name is DS)
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 2
SYMBOLGEN:  Macro variable DS resolves to DAYSH600001
MPRINT(APP):   data DAYSH600001;
SYMBOLGEN:  Macro variable DS resolves to DAYSH600001
MPRINT(APP):   id="DAYSH600001";
SYMBOLGEN:  Macro variable DS resolves to DAYSH600001
MPRINT(APP):   set DAYSH600001;
MPRINT(APP):   run;

NOTE: There were 1 observations read from the data set WORK.DAYSH600001.
NOTE: The data set WORK.DAYSH600001 has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


SYMBOLGEN:  Macro variable DS resolves to DAYSH600001
MPRINT(APP):   proc append base=all data=DAYSH600001 force;
MPRINT(APP):   run;

NOTE: Appending WORK.DAYSH600001 to WORK.ALL.
NOTE: There were 1 observations read from the data set WORK.DAYSH600001.
NOTE: 1 observations added.
NOTE: The data set WORK.ALL has 2 observations and 6 variables.
NOTE: PROCEDURE APPEND used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


MLOGIC(APP):  %LET (variable name is I)
SYMBOLGEN:  Macro variable I resolves to 2
MLOGIC(APP):  %PUT %scan(&dslist,&i)
SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 3

SYMBOLGEN:  Macro variable DSLIST resolves to DAYSH600000 DAYSH600001
SYMBOLGEN:  Macro variable I resolves to 3
MLOGIC(APP):  %DO %WHILE() condition is FALSE; loop will not iterate again.
MLOGIC(APP):  Ending execution.
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

使用道具

10
蓝莓夹心 发表于 2012-6-13 17:40:35 |只看作者 |坛友微信交流群
你input的时候用filename也可以的

data all;
length fn $100.;
length filename $100.;
infile 'path\*' delimiter=   filename=fn;
input ......;
id=scan(fn,2,'\');
run;
类似这种方法去输入数据文件,就直接合并了

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
yugao1986 + 1 + 1 + 1 分析的有道理

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

使用道具

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

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

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

GMT+8, 2024-4-28 02:29