自动变量存在宏

发布于 2025-01-29 11:01:44 字数 859 浏览 1 评论 0原文

我正在尝试技巧,以查看是否仍然存在变量并为其分配一个空值,

%macro VarExist(ds, var);
    %local rc dsid result;
    %let dsid =%sysfunc(open(&ds));
    
    %if %sysfunc(varnum(&dsid,&var)) > 0 %then %do;
        %let result =1;
        %put NOTE: Var &var exists in &ds;
    %end;
    %else %do;
        %let result= 0;
        %put NOTE: Variable &var was dropped at SDTM level per CDISC Compliance.
             Null value will be assigned.;
    
        data AE2;
            set work.&ds;
            &VAR=.;
        RUN;
    %END;
    %let rc=%sysfunc(close(&dsid));
%MEND VarExist;
    
%VarExist(ae1,AESDTH);

是否有一种方法可以自动分配变量实际字符/数字来源? vtype也许或vvalue?。另外,对于AE2,我可以做类似& ds.n的事情,还是只是在原始& ds dataset中自动分配它。我只做了另一个数据集,以进行现实测试。有什么想法吗?链接到相关论文?

I'm trying to finesse a macro I did to see if a variable is still present and to assign it a null value

%macro VarExist(ds, var);
    %local rc dsid result;
    %let dsid =%sysfunc(open(&ds));
    
    %if %sysfunc(varnum(&dsid,&var)) > 0 %then %do;
        %let result =1;
        %put NOTE: Var &var exists in &ds;
    %end;
    %else %do;
        %let result= 0;
        %put NOTE: Variable &var was dropped at SDTM level per CDISC Compliance.
             Null value will be assigned.;
    
        data AE2;
            set work.&ds;
            &VAR=.;
        RUN;
    %END;
    %let rc=%sysfunc(close(&dsid));
%MEND VarExist;
    
%VarExist(ae1,AESDTH);

Is there a way to automatically assign the variables actual character/numeric origin? vtype maybe or vvalue?. Also for the AE2, can I do something like &ds.n or even just automatically assign it within the original &ds dataset. I only did another dataset to reality test that it was working. Any thoughts? Links to relevant papers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2025-02-05 11:01:44

似乎不需要测试该变量是否存在。

 data ae2;
   set ae1;
   length AESDTH 8;
 run;

There does not appear to be any need to test if the variable exists or not.

 data ae2;
   set ae1;
   length AESDTH 8;
 run;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文