Hi,
I am getting the below error when executing my sas program when I am trying to make the macro variable T01_UN_KEY1 to Global
Error: Attempt to %GLOBAL a name (T01_UN_KEY1) which exists in a local environment
So I changed my code something like below
%DO I=1 %TO &KEY_STRING_CNT.;
%GLOBAL G_T01_UN_KEY&I;
%LET T01_UN_KEY&I = && G_T01_UN_KEY&I..;
%END;
Now I am not getting the error. But the values in dataset for the variable KEYWORD1 are not correct. It just gives commas without values when it is supposed to have values separated by commas.
Could you please resolve my problem. It is very urgent.
Below is the program for your reference.
%let T01_ADDKEY = TEST,MISC,OTHER;
DATA UNUS_KEY;
KEY=SYMGET("T01_ADDKEY");
KEY=UPCASE(KEY);
count= count(KEY,',');
COUNT_NEW=COUNT+1;
do i = 1 to count +1;
KEY1 = trim(left(scan(KEY,i,',')));
OUTPUT;
end;
RUN;
DATA UNUS_KEY1;
SET UNUS_KEY;
CALL SYMPUT(COMPRESS('T01_UN_KEY'||_N_),TRIM(LEFT(KEY1)));
RUN;
%LET KEY=%SYSFUNC(OPEN(SASDATA.UNUS_KEY1));
%LET KEY_STRING_CNT=%SYSFUNC(ATTRN(&KEY,NOBS));
%LET RC=%SYSFUNC(CLOSE(&KEY));
DATA SASDATA.UNUSUAL_TEMP;
SET SASDATA.&CLIENT._NOEX;
LENGTH KEYWORD1 $1000. TEMP $1. ;
%DO I=1 %TO &KEY_STRING_CNT.;
%GLOBAL G_T01_UN_KEY&I;
%LET T01_UN_KEY&I = && G_T01_UN_KEY&I..;
%END;
%IF &KEY_STRING_CNT. > 0 %THEN %DO;
%DO I =1 %TO &KEY_STRING_CNT.;
IF INDEX(UPCASE(ACCT_DESCR),"&&T01_UN_KEY&I.") > 0 THEN DO;
KEYWORD1 = TRIM(LEFT(KEYWORD1)) || TEMP || %STR("&&T01_UN_KEY&I.");
TEMP=",";
END;
%END;
OUTPUT SASDATA.UNUSUAL_TEMP;
%END;
RUN;
... View more