Sas 如何从表中选择单个值用于比较(大于/小于)?

Sas 如何从表中选择单个值用于比较(大于/小于)?,sas,Sas,我正在把一些代码交给一位同事,每天运行这些代码生成报告 每个月一次新的周期开始,我们必须更新周期开始日期的代码 data mtd_table; set ytd_table; where entry_date> '10Mar2021'd; /*different every month*/ run; 因为从现在起,他将运行它们,以及其他团队的其他报告,我不想每个月都打扰他来调整代码。所以我设计了这个: 我快一个月了 data shared1.cycle_start_date; cycle_

我正在把一些代码交给一位同事,每天运行这些代码生成报告

每个月一次新的周期开始,我们必须更新周期开始日期的代码

data mtd_table;
set ytd_table;
where entry_date> '10Mar2021'd; /*different every month*/
run;
因为从现在起,他将运行它们,以及其他团队的其他报告,我不想每个月都打扰他来调整代码。所以我设计了这个:

我快一个月了

data shared1.cycle_start_date;
cycle_start_date='10Mar2021'd;
run;
他每天都跑

data mtd_table;
set ytd_table;
where entry_date>/*(select cycle_start_date from shared1.cycle_start_date)*/;
run;

我不知道如何正确实现这个从shared1.cycle\u start\u date部分选择cycle\u start\u date,因为它来自proc sql。非常感谢您的帮助。

一个可能的解决方案是将共享库shared1中的cycle_start_date表中的日期放入宏变量date中,该宏变量将在数据步骤中用于根据entry_date变量筛选ytd_表

proc sql noprint;
select cycle_start_date into :date 
from shared1.cycle_start_date;
quit;

data mtd_table;
set ytd_table;
where entry_date > &date.;
run;

一种可能的解决方案是将共享库shared1中的cycle_start_date表中的日期放入宏变量date中,该宏变量将在数据步骤中用于根据entry_date变量筛选ytd_表

proc sql noprint;
select cycle_start_date into :date 
from shared1.cycle_start_date;
quit;

data mtd_table;
set ytd_table;
where entry_date > &date.;
run;

当您将程序参数存储在名为“控制数据”的数据集中时,一个用例是让稍后的代码将值提取到宏变量中,此时其他代码可以解析宏变量,以便在自动编译和运行时替换。将值提取到宏变量中的两种方法是:

Proc SQL,选择。。。分为:、和 数据为空,调用SYMPUT; 不要忘记,宏解析将宏变量替换为源代码文本。宏变量中的日期可以是SAS数据值—SAS日期整数的文本表示形式,也可以是日期文字的一部分—当用作日期值时,将解析为源日期文字(&D)的文本。当您希望在when输出中将日期值显示为人类可读时,使用日期文字部分;例如:标题周期开始:&周期开始日期

控制你的数据

重新生成或编辑数据集中的值将其命名为参数以使其更有用

data shared1.parameters;
  cycle_start_date = '10Mar2021'd;  * stored as a SAS date value (integer);
run;
注意:某些控制数据布局使用名称/值组织,每个参数有一行

其他

将日期值提取为SAS日期值文本和日期文字文本部分并使用

proc sql noprint;
  select 
    cycle_start_date
  , cycle_start_date format=date11.
  into
    :cycle_start_date_value trimmed
  , :cycle_start_date_literal trimmed
  from
    shared1.parameters
  ;

%put &=cycle_start_date_value;
%put &=cycle_start_date_literal;

/* 
 * will log the macro variable value as follows:
 * CYCLE_START_DATE_VALUE=22349 and
 * CYCLE_START_DATE_LITERAL=10-MAR2021
 */

data ...
  set ...;
  where date >= &cycle_start_date; *resolve parameter as text representation of a SAS date value (integer);
...

title "Cycle starts: &cycle_start_date_literal";

proc print data=...; * title in output shows human readable part of date;
run;
另一种方法是使用其他人包含%的公共源代码文件。您可以通过任何需要的过程来编辑或重新创建参数文件

参数.sas

使用


当您将程序参数存储在名为“控制数据”的数据集中时,一个用例是让稍后的代码将值提取到宏变量中,此时其他代码可以解析宏变量,以便在自动编译和运行时替换。将值提取到宏变量中的两种方法是:

Proc SQL,选择。。。分为:、和 数据为空,调用SYMPUT; 不要忘记,宏解析将宏变量替换为源代码文本。宏变量中的日期可以是SAS数据值—SAS日期整数的文本表示形式,也可以是日期文字的一部分—当用作日期值时,将解析为源日期文字(&D)的文本。当您希望在when输出中将日期值显示为人类可读时,使用日期文字部分;例如:标题周期开始:&周期开始日期

控制你的数据

重新生成或编辑数据集中的值将其命名为参数以使其更有用

data shared1.parameters;
  cycle_start_date = '10Mar2021'd;  * stored as a SAS date value (integer);
run;
注意:某些控制数据布局使用名称/值组织,每个参数有一行

其他

将日期值提取为SAS日期值文本和日期文字文本部分并使用

proc sql noprint;
  select 
    cycle_start_date
  , cycle_start_date format=date11.
  into
    :cycle_start_date_value trimmed
  , :cycle_start_date_literal trimmed
  from
    shared1.parameters
  ;

%put &=cycle_start_date_value;
%put &=cycle_start_date_literal;

/* 
 * will log the macro variable value as follows:
 * CYCLE_START_DATE_VALUE=22349 and
 * CYCLE_START_DATE_LITERAL=10-MAR2021
 */

data ...
  set ...;
  where date >= &cycle_start_date; *resolve parameter as text representation of a SAS date value (integer);
...

title "Cycle starts: &cycle_start_date_literal";

proc print data=...; * title in output shows human readable part of date;
run;
另一种方法是使用其他人包含%的公共源代码文件。您可以通过任何需要的过程来编辑或重新创建参数文件

参数.sas

使用


这是非常有益的!这是非常有益的!