SAS:按年将数据导出到多个 csv 文件 [英] SAS: export data to multiple csv file by year

查看:35
本文介绍了SAS:按年将数据导出到多个 csv 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SAS 中有一个数据集,其中包含 20 年的数据.我想每年导出到 csv 文件.有什么简单的方法吗?

I have a dataset in SAS, which contains 20 years of data. I want to export to csv file for each year. Is there any easy way to do it?

这是我一年来一直在做的事情(这很幼稚):

Here is what I'm doing for one year now (which is naive):

过程导出
data=ds (where=(year=2011)) outfile='ds2011.csv' DBMS=CSV 替换;
运行;

proc export
data=ds (where=(year=2011)) outfile='ds2011.csv' DBMS=CSV replace;
run;

非常感谢!

推荐答案

非宏选项:

您可以在数据步骤中使用 file 语句写出各种类型的文本或分隔文件.使用 filevar 选项可以为变量的每个值创建一个文件,如下所示.

You can use the file statement in a data step to write out various types of text or delimited files. Using the filevar option allows you to create one file for each value of a variable as is done below.

yourdata 替换为您的数据集,并将 write_location 替换为您希望文件的位置.

Replace yourdata with your dataset and write_location with where you want the file to go.

data _null_;
  set yourdata;
  length fv $ 200;
  fv = "\write_location\" || TRIM(put(year,4.)) || ".csv";
  file write filevar=fv dsd dlm=',' lrecl=32000 ;
  put (_all_) (:);
run;

这篇关于SAS:按年将数据导出到多个 csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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