我有以下csv文件,我需要将它们读入SAS数据集。 另外,我需要指定列名。 另外,我需要列是数字的,但有些列有数字和字符值。
文件夹aa:abc1.csv,abc2.csv,abc3.csv,...... 文件夹bb:abc1.csv,abc2.csv,abc3.csv,...... 文件夹cc:abc1.csv,abc2.csv,abc3.csv,......
答案 0 :(得分:2)
您也可以通过以下方式完成。
创建一个宏,使其名称保留为“into”子句。
proc sql;
select name_list into :name separated by '*' from work.name;
%let count2 = &sqlobs;
quit;
创建如下的宏。
%macro yy;
%do i = 1 %to &count2;
%let j = %scan(&name,&i,*);
proc import out = &j datafile="folderwhereallcsvfilesarekept\&j..csv"
dbms=csv replace;
getnames = yes;
run;
%end;
%mend;
答案 1 :(得分:1)
这不是一个完整的答案,但它会让你开始。您必须添加一个外部循环来浏览要从中获取文件的不同目录。
/*List the files in a directory for use in a data step. This is written for Windows. Other operating systems will be slightly different. */
filename fnames pipe 'dir c:\temp\* /b';
/* Create a data set with one observation for each file name */
data fnames;
infile fnames pad missover;
input @1 filename $255.;
n=_n_;
run;
/* Store the number of files in a macro variable "num" */
proc sql noprint; select count(filename) into :num; quit;
/* Create a macro to iterate over the filenames, read them in, and append to a data set. */
%macro doit;
%do i=1 %to #
proc sql noprint;
select filename into :filename from fnames where n=&i;
quit;
data ds;
infile &filename;
input ...list of variable names...;
...other statements...;
run;
proc append data=ds base=final; run;
%end;
%mend;
%doit;