使用函数或计算来引用 SAS 字段名称?

问题描述 投票:0回答:1

我需要填充一系列标题为 M0、M1、M2 等的列。下面是我已经制定出的长期逻辑,但现在我想简化代码。了解我如何首先计算两个日期字段之间的月份,以了解要填充哪一列。

if intck('month', start_dt, today_dt) = 0 then M0 = "Blue";
if intck('month', start_dt, today_dt) = 1 then M1 = "Blue";
if intck('month', start_dt, today_dt) = 2 then M2 = "Blue";

从概念上讲,我宁愿在一行代码上做这样的事情:

"M"||intck('month', start_dt, today_dt) = "Blue";

所以我想“计算”正确的列名称。

感谢您的帮助!

sas
1个回答
0
投票

这就是 ARRAY 的用途。

array month [0:3] m0-m3;
month[intck('month', start_dt, today_dt)]= "Blue";
© www.soinside.com 2019 - 2024. All rights reserved.