SAS 检查表中是否存在列

发布于 2025-01-10 14:06:35 字数 404 浏览 0 评论 0原文

我想制作一个宏来检查 col_to_check 中的所有列是否都在表中,并且如果其中一列不退出,我想退出 SAS

我尝试这样做:

%let col_to_check = ID SEG AGE;

%宏检查(表,col_to_check);

%local count;
%let count=0;

%DO i_=1 %TO %sysfunc(countw(&col_to_check.," "));  

        %LET col=%SCAN(&col_to_check.,&i_.," ");
        %if ( %varexist(&table.,&col.) = 1) %then endsas;
%END;

%修复检查;

I want to make a macro That check if all the columns in col_to_check are in Table and I want exit SAS if one of these columns doesn't exit

I try this:

%let col_to_check = ID SEG AGE;

%MACRO check(table , col_to_check);

%local count;
%let count=0;

%DO i_=1 %TO %sysfunc(countw(&col_to_check.," "));  

        %LET col=%SCAN(&col_to_check.,&i_.," ");
        %if ( %varexist(&table.,&col.) = 1) %then endsas;
%END;

%MEND check;

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

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

发布评论

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

评论(1

赢得她心 2025-01-17 14:06:35

使用 sashelp 库的 vcolumn 表。

%macro check(lib, table, col_to_check);
    %let nb_col = %sysfunc(countw(&col_to_check., %quote( )));
    %let col_names = "%sysfunc(tranwrd(&col_to_check.,%str( )," "))";

    proc sql noprint;
        select count(distinct name) into :nb 
        from sashelp.vcolumn where upcase(name) in (&col_names.) 
           and upcase(libname)="&lib." 
           and upcase(memname)="&table.";
    quit;

    %if &nb. ^=&nb_col. %then
        %goto end_pg;
    %else
        %do;
            %put do stuff;
        %end;
%end_pg:
%mend;

%check(SASHELP, CLASS, SEX WEIGHT NAME AGE);

PS:“退出 SAS”是什么意思?您可以轻松地将 %goto 替换为 %ABORT< /a>

Use the vcolumn table of the sashelp library.

%macro check(lib, table, col_to_check);
    %let nb_col = %sysfunc(countw(&col_to_check., %quote( )));
    %let col_names = "%sysfunc(tranwrd(&col_to_check.,%str( )," "))";

    proc sql noprint;
        select count(distinct name) into :nb 
        from sashelp.vcolumn where upcase(name) in (&col_names.) 
           and upcase(libname)="&lib." 
           and upcase(memname)="&table.";
    quit;

    %if &nb. ^=&nb_col. %then
        %goto end_pg;
    %else
        %do;
            %put do stuff;
        %end;
%end_pg:
%mend;

%check(SASHELP, CLASS, SEX WEIGHT NAME AGE);

PS: What do you mean by "exit SAS"? You could easily replace the %goto by %ABORT

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