【问题标题】:SAS - today() in a proc freq where clauseSAS - proc freq where 子句中的 today()
【发布时间】:2017-08-30 22:34:22
【问题描述】:

我正在使用 SAS 并尝试自动获取今天的日期并将其放入 proc freq 的 where 子句中。

看起来像这样:

proc freq data=data_name;
  tables date_col;
  where date_col > '30aug2017'd;
run;

我想要今天()而不是 30aug2017,但我正在努力让它工作,我已经尝试过:

data create_date;
current1 = today();
format current1 date9.;
run;

proc freq data=data_name;
  tables date_col;
  where date_col > current1;
run;

但我得到的错误是变量不在文件中

任何帮助表示赞赏,

大家好

【问题讨论】:

    标签: sas


    【解决方案1】:

    您可以在 WHERE 语句中直接使用 TODAY()。

     where date_col > today();
    

    【讨论】:

    • 我之前尝试过,但认为它不起作用。刚刚意识到这是因为今天的数据不可用....
    • 我建议使用%sysfunc(today()) 来避免函数在每条记录上触发
    • 我通常使用 x 天这样的时间段:date_col > date() - 20,在这种情况下 x 是 20。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多