从SAS列获取月份和财政年度

huangapple go评论95阅读模式
英文:

Getting month and fiscal year from columns SAS

问题

FISCAL_YEAR MTH Month_Name
FY2018 6 六月
FY2017 5 五月
FY2022 10 十月

我想要获取当前财政年度(例如,对于此实例为FY2023,但明年为FY2024),以及一个月前(即当前MTH = 7和/或Month_Name = 'JUL')。如何在SAS PROC SQL中实现?

英文:

I have a table with the following type of data

FISCAL_YEAR MTH Month_Name
FY2018 6 JUN
FY2017 5 MAY
FY2022 10 OCT

I want to get current fiscal year (i.e. FY2023 for this instance but FY2024 next year) and 1 month previous (i.e. currently MTH = 7 and/or Month_Name = 'JUL'). How do I get that in SAS PROC SQL?

答案1

得分: 2

如果您想计算当前财政年度,您可以使用带有偏移的INTNX函数。以下将计算当前财政年度,使用10月1日作为财政年度分界点:

%let FY= %sysfunc(year(%sysfunc(intnx(year.10, %sysfunc(today()), 0, e)))) ;
%let PriorMonth= %sysfunc(month(%sysfunc(intnx(month,%sysfunc(today()),-1,b)))) ;

%put &=FY &=PriorMonth ;

返回结果:

FY=2023 PRIORMONTH=7

所以如果您喜欢这个方法,那么在您的PROC SQL中,您可以使用以下的WHERE子句:

where Fiscal_Year="FY&FY" and MTH=&PriorMonth
英文:

Still not clear on your question but...

If you want to calculate the current fiscal year, you can use INTNX with an offset. The following will calculate current fiscal year, using Oct 1 as fiscal year cutpoint:

%let FY= %sysfunc(year(%sysfunc(intnx(year.10, %sysfunc(today()), 0, e)))) ;
%let PriorMonth= %sysfunc(month(%sysfunc(intnx(month,%sysfunc(today()),-1,b)))) ;

%put &=FY &=PriorMonth ;

Returns:

FY=2023 PRIORMONTH=7

So if you like that, then in your PROC SQL you can use a WHERE clause like:

where Fiscal_Year="FY&FY" and MTH=&PriorMonth

huangapple
  • 本文由 发表于 2023年8月5日 00:18:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定