SAS:ERROR尝试在PRXCHANGE中更改字符串的值

时间:2018-02-27 18:27:47

标签: sas

我有这段代码:

%global nb_usag;
%global usager_entr;

%let nb_usag=0;
%syslput nb_usag=&nb_usag;

%let usager_entr=u;

PROC SQL noprint ;
    select count(distinct no_usager_entr) into :nb_usag  from &lib..INSCRITS_USA_1
    ;
quit;

data _null_;
    if &nb_usag > 0 then do;
        call execute
            ("PROC SQL noprint ;
            select distinct no_usager_entr INTO :usager_entr separated by ','

            from &lib..INSCRITS_USA_1;")
        ;
        if &usager_entr ne "u" then do;
            call prxchange('s/,/\",\"',-1,&usager_entr);
        end;
    end;
run;

%let usager_entr="&usager_entr";
%syslput usager_entr=&usager_entr;
%put &nb_usag;
%put &usager_entr;

但代码会为函数prxchange生成此错误:

ERROR 135-185: Attempt to change the value of the constant 's/,/\",\"' in the PRXCHANGE subroutine call.

我做错了什么?

我想在变量usager_entr中用“,”修改每一个。

例如,如果usager_entr = 12121212,34343434,56565656它将成为12121212","34343434","56565656

在我的情况下,table& lib..INSCRITS_USA_1为空,然后是nb_usag = 0.

谢谢!

2 个答案:

答案 0 :(得分:3)

太多鬼混了!而是直接从0x10

创建双引号值列表

假设列表将在后面的子句中使用构造Proc SQL

IN (&myList)

需要冗余值,因为如果它是空的,您稍后会生成%let usager_entr_dq_csv_list = "redundant safety value that will never match anything"; PROC SQL noprint ; select distinct quote(trim(no_usager_entr)) INTO :usager_entr_dq_csv_list separated by ',' from &lib..INSCRITS_USA_1; 并且语法错误。

如果在传递SQL中使用该列表,您将需要使用IN ()函数的其他参数来使用单引号绑定值。

答案 1 :(得分:2)

要修改您的宏变量,从usager_entr = 12121212,34343434,56565656到&#34; 12121212&#34;,&#34; 34343434&#34;,&#34; 56565656&#34;,您可以使用prxchange:< / p>

topic_id