SAS中文论坛
标题:
用宏批量导入文件,有问题,请高手指点!
[打印本页]
作者:
shiyiming
时间:
2008-12-5 20:34
标题:
用宏批量导入文件,有问题,请高手指点!
任务要求:
有100个TXT文件,文件命不规范,都是60开头(上海股票代码),但格式完全相同,单个文件读入sas没有问题。
现在想通过宏导入,每个TXT文件对应生成一个数据集。
初步设想:
1,在该文件目录下键入dir *.txt /b >ex.txt,将100个txt文件名导入文本文件all.txt中
2.编写宏及程序
%macro a(stockcode);
data a&stockcode;
infile "d:\Level-2 and Topview\0710\All_2007-10-08\Stock_details\&stockcode..txt" firstobs=2;
input code $ cjtime price vol amount;
informat cjtime time.;
format cjtime time.;
run;
%mend a;
%include "d:\Level-2 and Topview\0710\All_2007-10-08\Stock_details\all.txt";
run;
3.运行错误提示:
351 %macro a(stockcode);
352 data a&stockcode;
353 infile "d:\Level-2 and Topview\0710\All_2007-10-08\Stock_details\&stockcode..txt" firstobs=2;
354 input code $ cjtime price vol amount;
355 informat cjtime time.;
356 format cjtime time.;
357 run;
358 %mend a;
359 %include "d:\Level-2 and Topview\0710\All_2007-10-08\Stock_details\all.txt";
360 +600000.txt
-------
180
ERROR 180-322: 语句无效或未按正确顺序使用。
461 run;
本人初步估计出在%include这语句上,如果我把最后一句改成%a(600050);就可以运行了,但这个参数要自己输入,就失去宏的意义了。
%include语句是通过all.txt文件来传递参数的吗?
恳请高手指教!
作者:
shiyiming
时间:
2008-12-10 00:27
标题:
Re: 用宏批量导入文件,有问题,请高手指点!
俺单知道%include不是这个用法,其它就一概不知啦。
作者:
shiyiming
时间:
2008-12-14 21:05
标题:
Re: 用宏批量导入文件,有问题,请高手指点!
%macro a(stockcode);
data a&stockcode;
infile "d:\&stockcode..txt" ;
input code $ cjtime price;
run;
%mend a;
data _null_;
infile 'd:\all.txt';
input file $;
call execute('%a('||file||');');
run;
把你的问题简单化,希望对你有帮助。
欢迎光临 SAS中文论坛 (https://mysas.net/forum/)
Powered by Discuz! X3.2