我如何在SAS中写下减去日期的过滤器

发布于 2025-01-25 17:36:14 字数 313 浏览 3 评论 0原文

您好Stackoverflow社区...希望您可以为这个SAS问题提供帮助。

我需要为表格创建一个过滤器,该表仅退还那些从去年前进的记录。

我想获得类似的内容:

data want;
set have;
where expire_date >= current(date) - 1year:
run;

Expire_Date列的格式为03May2022(date9。format)...我尝试将日期转换为数字,然后减去365,但我想有一个更好的解决方案。

有人可以照亮我吗?

提前致谢

Hello Stackoverflow community... hope you can help with this sas question.

I need to create a filter for a table which gives back only those records that are active from last year forward.

I would like to obtain something like :

data want;
set have;
where expire_date >= current(date) - 1year:
run;

the format of the expire_date column is 03MAY2022 (date9. format)... I tried to transform the date into a number and then subtracting 365, but i guess there is a better solution.

can someone illuminate me?

thanks in advance

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

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

发布评论

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

评论(2

∝单色的世界 2025-02-01 17:36:14

我认为您正在搜索intnx()函数:

data a;
  format num_date num_date_minus_year DATE9.;
  char_date="03MAY2022";
  num_date = inputn (char_date, "DATE9.");
  num_date_minus_year = intnx ('YEAR', num_date, -1, "SAME");
  put num_date= num_date_minus_year=;
run;

输出:

num_date=03MAY2022 num_date_minus_year=03MAY2021

I think you are searching for the INTNX() function:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm#n1lchasgjah7ran0z2wlmsbfwdx2
For example:

data a;
  format num_date num_date_minus_year DATE9.;
  char_date="03MAY2022";
  num_date = inputn (char_date, "DATE9.");
  num_date_minus_year = intnx ('YEAR', num_date, -1, "SAME");
  put num_date= num_date_minus_year=;
run;

Output:

num_date=03MAY2022 num_date_minus_year=03MAY2021
爱本泡沫多脆弱 2025-02-01 17:36:14

您可以使用date()函数获取当前日期。

您想要一年或365天吗?

使用日期间隔使用intnx()函数。

where expire_date >= intnx('year',date(),-1,'same') ;

要使用固定的天数,只是减去数字。

where expire_date >= date() - 365 ;

You can get the current date using the DATE() function.

Do you want one YEAR or 365 days?

To use a date interval use the INTNX() function.

where expire_date >= intnx('year',date(),-1,'same') ;

To use a fixed number of days just subtract the number.

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