SAS,从数据集列创建文件名
是否可以根据存储在数据集列中的值创建文件名?我所追求的是这样的:
/*
other code here, assume work.users looks like
user_id
ImageData
*/
data _null_;
set work.users;
file_name=cat('/home/me/', trim(user_id), '.jpg');
file file_name NOPRINT;
put ImageData;
run;
目前我正在尝试用宏来做到这一点,但我没有任何运气。
is it possible to create a filename from a value stored in a dataset column? What i'm after is something like:
/*
other code here, assume work.users looks like
user_id
ImageData
*/
data _null_;
set work.users;
file_name=cat('/home/me/', trim(user_id), '.jpg');
file file_name NOPRINT;
put ImageData;
run;
at the moment i'm trying to do it with macros but i'm not having any luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您需要首先创建 file_name 变量,然后可以在新数据步骤中使用
filevar=
选项动态写入文件。因此,首先在
work.users
中创建 file_name:然后使用 filevar= 选项执行您想要执行的操作:
请注意,
dummy
在使用 < 时只是一个占位符code>filevar= 方法。To do this, you'll need to create the file_name variable first, and then you can use the
filevar=
option in a new data step to dynamically write to the files.So, first create file_name in
work.users
:Then do what you're trying to do using the filevar= option:
Note that
dummy
is just a placeholder when using thefilevar=
method.如果您想使用宏来执行此操作:
但是,这假设
work.users
中只有一个观察结果,我猜这不是真的。如果您想为每个观察输出一个文件,请将其放入宏中:这里,参数 &n 是数据集中的观察数量。您可以通过编程方式获取它,但对于当前目的而言,只需将其手动传递给宏会更容易。
If you want to do this with macros:
However, this assumes there is only one observation in
work.users
, which I'm guessing is not true. If you want to output a file for each observation, roll it into a macro:Here, the argument &n is the number of observations in your dataset. You could obtain it programmatically, but it's easier for current purposes just to pass it manually to the macro.