股票数据合并

一个月在论坛上提问过个股数据合并问题,问题如下:

现有100只股票数据txt,命名形如: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
    ...

感谢yamat/webgu/蓝莓夹心等网友的解答,解决方法如下:

 
1.个人数据为sas格式的数据

libname yu "E:\yugao\datasets\datasets\day\hsa";

proc sql noprint;
   select memname into:dsnlist separated by " "
      from dictionary.tables
      where libname="YU";
quit;
data tar;
   length id $ 32;
   set yu.daysh600000;
   stop;
run;
%macro inserttable(dsnlist);
%let n=%eval(%sysfunc(count(&dsnlist,%str( )))+1);
%do i=1 %to &n;
   %let dsn=%scan(&dsnlist,&i);
   proc sql;
      insert into tar
         select  "&dsn",
                   Time,
                   Open,
                   High,
                   Low,
                   Close,
                   Volume,
                   Amount
          from yu.&dsn;
   quit;
%end;
%mend;
%inserttable(dsnlist=&dsnlist);

*另一种思路;

/*macro for appending data set*/
options  symbolgen mprint mlogic;
%macro app(inlib);
proc sql;
  select  distinct memname  into : dslist separated by " "
  from sashelp.vcolumn
  where libname=%upcase("&inlib");
quit;

  %let i=1;
  %do %while(%scan(&dslist,&i) ne );
     %let ds=%scan(&dslist,&i);
       data &ds;
           id="&ds";
                set  &ds;
       run;
 proc append base=all  data=&ds  force;
 run;

  %let i=%eval(&i+1);
  %put  %scan(&dslist,&i);
  %end;
%mend app;

/*test: cation,do it only once*/
%app(YU);

 

2.文件为txt等格式文件,利用infile命令中的filename参数

data all;
   length fn $100.;
   length filename $100.;
   infile 'e:\tmp\*' delimiter=   filename=fn;
   input date $ open high low close volume amount;
   id=scan(fn,2,'\');
run;

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值