表达“PUT 所有变量"在导出 SAS 数据的数据步骤中 [英] Express "PUT all variables" in a data step to export SAS data
问题描述
目标:使用数据步骤将整个 SAS 数据集导出到以制表符分隔的文本文件.
Goal: export an entire SAS dataset to a tab-delimited text file using a data step.
问题:在我能找到的每个示例中,例如 这个,必须在 PUT 语句之后的数据步骤中指定每个变量.难道没有一种简单的方法来询问所有"变量吗?
Problem: In every example that I can find, such as this one, one must specify every variable in the data step following the PUT statement. Isn't there a simple method to just ask for "all" of the variables?
我已经尝试过使用 PUT _ALL_
,但这在输出的每一行中都包含变量名称,而不是仅仅输出值.
I have already tried using PUT _ALL_
, but that includes the variable names in every row of the output, instead of just outputtin the values.
推荐答案
如果你想在数据步骤中做,并且不想指定东西,但真的不想PROC EXPORT代码> 为您做出决定,并且拥有相当容易指定的数据(没有什么像您想要的特殊格式的日期那样花哨的数据),您可以这样做.
If you want to do it in a data step, AND don't want to specify things, but really don't want PROC EXPORT
making decisions for you, AND have data that's reasonably easily specified (nothing fancy like dates you want in a special format), you can do this.
proc sql;
select name into :namelist separated by ' '
from dictionary.columns
where libname='SASHELP' and memname='CLASS'; *these are the libname/dataset name you want;
quit;
filename blah temp;
data _null_;
set sashelp.class;
file blah dlm='09'x;
put &namelist.;
run;
您可以根据需要通过修改sql查询对其进行一些自定义(例如,如果您有一组带有_date
的变量,也许您可以对其进行修改以添加name||':date9.'
在那些的 sql 查询中.
You can customize it some depending on your needs by modifying the sql query (such as if you have a set of variables with _date
perhaps you could modify it to add name||' :date9.'
in the sql query for those.
请注意,dictionary.columns 中的 libname/memname/name 字段通常为大写.我不认为它们总是大写,但它们几乎总是如此.(我相信,例如一些 RDBMS 可以覆盖它).
Note that the libname/memname/name fields in dictionary.columns are typically upper case. They are not always upper case, I don't think, but they almost always are. (Some RDBMSs for example can override this, I believe).
这篇关于表达“PUT 所有变量"在导出 SAS 数据的数据步骤中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!