循环遍历字符串并读入文件并保存 [英] Loop over strings and read in files and save

查看:708
本文介绍了循环遍历字符串并读入文件并保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SAS很陌生。我有一堆csv格式的文件,我想读入SAS。我需要逐个阅读它们,并将它们单独或最好保存在一个巨大的文件中。 (虽然文件可能非常大......不知道如何最好地解决这个问题 - MySQL也许?)

I am pretty new to SAS. I have a bunch of files that are in csv format that I want to read into SAS. I need to read them in one-by-one and save them, either individually or preferably in one huge file. (Although the file might be really large...not sure how to best deal with this - MySQL maybe?)

假设文件命名如下:

file97.csv
file98.csv
file99.csv
file00.csv
file01.csv
file02.csv

如何循环循环语句中的97,98,99,00,01,02

如果我只导入,请说 file97.csv ,代码类似于:

If I import just, say file97.csv, the code is something like:

PROC IMPORT OUT= WORK.data97 
            DATAFILE= "\...\file97.csv" 
            DBMS=CSV REPLACE;
     GETNAMES=YES;
     DATAROW=2; 
RUN;

我会写什么代码来循环?我基本上只需要更改 97

What code would I write to loop? I basically need to change only the 97s.

推荐答案

由于你想要循环 Proc import 你将不得不,因为你数字97,98,99,00,01,02 不连续你会必须使用解决方法。

Since you want to loop over Proc import you will have to Macros for that, also since you Numbers 97, 98, 99, 00, 01, 02 are not consecutive you will have to use a workaround.

%let files=97,98,99,00,01,02;
%macro loop_over;
%do i=1 %to %sysfunc(countw("&files."));
PROC IMPORT OUT= WORK.data%sysfunc(scan("&files.",&i.,",")) 
            DATAFILE= "\...\file%sysfunc(scan("&files.",&i.,",")).csv" 
            DBMS=CSV REPLACE;
     GETNAMES=YES;
     DATAROW=2; 
RUN;
%end;
%mend;
%loop_over;

这篇关于循环遍历字符串并读入文件并保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆