日期作为变量名

发布于 2024-11-13 09:16:51 字数 246 浏览 2 评论 0原文

我想使用日期作为变量名。我知道我需要在前面附加一个字符,而且这不是存储数据的好方法(这纯粹是为了报告美观)。我尝试过 %eval() 但无法解决。

%let var_date = '_'||today();
data date;
    %eval(&var_date) = .;
run;

我希望变量名称为 _02JUN2011。感谢您的任何帮助。

I'd like to use the date as a variable name. I understand I'll need to append a character to the front and also that it's not a good way to store data (it's purely for report aesthetics). I've tried %eval() but can't solve it.

%let var_date = '_'||today();
data date;
    %eval(&var_date) = .;
run;

I'd like the variable name to be _02JUN2011. Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脱离于你 2024-11-20 09:16:51

我认为您不想采取这种方法。您应该在 PROC REPORT(或任何其他报告 PROC)中使用标签,或者动态地旋转数据。也许如果您描述您所获得的数据和您想要的输出,这里的人们将能够帮助找到合适的解决方案。

不过,为了您的启发,以下代码可以完成您在帖子中尝试执行的操作:

%let var_date=_%sysfunc(today(),date9.);

data test;
  &var_date=.;
run;

I don't think you want to take this approach. You should use labels in PROC REPORT (or any other reporting PROC), or pivot your data dynamically instead. Perhaps if you describe the data you've got and the output you want, people here will be able to help find an appropriate solution.

For your edification though, the following code does what you're trying to do in your post:

%let var_date=_%sysfunc(today(),date9.);

data test;
  &var_date=.;
run;
离笑几人歌 2024-11-20 09:16:51

这就是我正在寻找的。这可以维护吗?

data date1;
    date = put(today(),date9.);
    text = '';
    do i = 1 to 5;
        output;
    end;
run;
proc transpose data = date1 out = date2;
    by i;
    id date;
    var text;
run;

This does what I'm looking for. Is this maintainable?

data date1;
    date = put(today(),date9.);
    text = '';
    do i = 1 to 5;
        output;
    end;
run;
proc transpose data = date1 out = date2;
    by i;
    id date;
    var text;
run;
ペ泪落弦音 2024-11-20 09:16:51

你真的想使用哈希 - 这不是可维护的代码..

You really want to use a hash - this is not maintainable code..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文