我正在尝试设置自动宏变量日期以在SAS HiveQL中运行脚本
我通常会在标准SAS查询中使用以下内容:
%let start_date = %sysfunc(intnx(month, "&sysdate"d, -1, B));
但是我需要将日期转换为yyyy-mm-dd格式才能运行HiveQL查询。
设置宏变量时,不确定如何将SAS日期转换为这种格式。
最欢迎您提供任何帮助。
答案 0 :(得分:2)
您可以在使用%sysfunc()
时指定格式:
%let start_date = %sysfunc(intnx(month, "&sysdate"d, -1, B), yymmdd10.);
答案 1 :(得分:1)
对于夜猫子,自动宏变量sysdate
是SAS会话开始的日期。长时间运行的会话可能需要使用函数today()
来获取当前日期。
远程传递日期文字也需要用单引号引起来。
%let remoteDateLiteralForPassThrough = %str(%')%sysfunc(putn(%sysfunc(today()),yymmdd10.))%str(%');
%put &=remoteDateLiteralPassThrough;
%let remoteDateTimeLiteralForPassThro = %str(%')%sysfunc(putn(%sysfunc(today()),yymmdd10.))T0:0:0%str(%');
%put &=remoteDateTimeLiteralForPassThro;
已添加:上个月的第一天为'yyyy-mm-dd'
%let start_date_num = %sysfunc(intnx(month, %sysfunc(today()), -1, B));
%let db_start_date = %str(%')%sysfunc(putn(&start_date_num,yymmdd10.))%str(%');