[英]SAS macro to get the last date of the current month
我想在 SAS 中使用宏來計算執行時當月的最后一天。
由於我對 SAS 宏還很陌生,所以我嘗試根據我在 inte.net 上找到的信息創建它。 %let last_day = %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),e), date9.));
但是當我執行它時它似乎不起作用。
您在 INTNX() function 調用中遺漏了間隔數。
使用 DATE9 生成的樣式中看起來像當月最后一天的字符串創建宏變量。 格式只需使用:
%let last_day = %sysfunc(intnx(month,%sysfunc(today()),0,e), date9.);
然后您可以使用該宏變量來生成字符串。 例如在 TITLE 語句中。
TITLE "End of the month is &last_day";
如果您想將其用作實際日期,則需要通過添加引號和字母 d 將其轉換為日期文字。
...
where date <= "&last_day"d ;
如果是這樣,不使用 DATE9 可能更簡單。 完全格式化並僅將自 1960 年以來的原始天數存儲在宏變量中。
%let last_day = %sysfunc(intnx(month,%sysfunc(today()),0,e));
...
where date <= &last_day ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.