【问题标题】:Dynamize range of SAS PROC SQL SELECT INTO macro creationSAS PROC SQL SELECT INTO 宏创建的动态范围
【发布时间】:2020-05-20 14:21:11
【问题描述】:

我想将多个观察结果放入一个自己的宏变量中。我会通过使用 select into :obs1 - :obs4 来做到这一点,但是,由于观察次数可能不同,我想动态化范围,我的代码如下所示:

proc sql;
    create table segments as select distinct substr(name,1,6) as segment from dictionary.columns
    where libname = 'WORK' and memname = 'ALL_CCFS' and name ne 'MONTH';
run;

proc sql noprint;
    select count(*) into: count from segments;
run;

proc sql noprint;
    select segment into :segment_1 - :segment_&count. from dictionary.columns;
run;

但是,这似乎不起作用...有什么建议吗?谢谢!

【问题讨论】:

    标签: sql select sas select-into


    【解决方案1】:
    • 将最后一个值留空/空白,SAS 将自动创建它们
    • 将其设置为一个大得离谱的数字,SAS 将只使用所需的值
    • 使用数据步骤创建它,您可以在其中动态增加数字(未显示)。

      proc sql noprint;
      select segment into :segment_1 - 
      from dictionary.columns;
      run;
      
      
      proc sql noprint;
      select segment into :segment_1 - :segment_999
      from dictionary.columns;
      run;
      

    【讨论】:

    • 并将自动宏变量 SQLOBS 保存到您自己的宏变量(例如 COUNT)中,以记住创建了多少个。
    猜你喜欢
    • 2018-10-31
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多