【问题标题】:Create a column in SAS using a macro variable使用宏变量在 SAS 中创建列
【发布时间】:2020-06-30 05:34:18
【问题描述】:

我正在尝试使用 SAS 中宏变量的字符串值创建列。 我有一个名为 want7 的数据集,其中有一列名为“ID”。我想创建一个名为 want8 的新数据集,其中包含一个名为“ID1”的新列,方法是将其动态链接到 &string1(如列名链接到 &string1),但列的值应等于“ID”的值'want7 中的列。我该怎么做呢?提前致谢。由于我对 SAS 比较陌生,所以我只复制和粘贴了我能写的内容。

 %let string1 = ID1;
 
 data want8; set want7;
 /*Something like &string1 = ID*
 run;

【问题讨论】:

  • 注意:所有 SAS 宏变量值都是字符(即文本)"Macro variables are tools that enable you to dynamically modify the text in a SAS program through symbolic substitution. You can assign large or small amounts of text to macro variables, and after that, you can use that text by simply referencing the variable that contains it."documentation.sas.com/…

标签: sas sas-macro


【解决方案1】:

以 sashelp.class 为例(因为它默认存在)。根据需要替换:

 %let string1 = ID1;
 
 data want8; 
    set sashelp.class;
        &string1 = age ;
 run;

这将重新读取数据集。如果您只想重命名,请查看数据集选项 rename=。请参阅 SAS 文档:https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695119.htm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多