Suppose I have a data set analogous to the following: DATA TEST; INFILE DATALINES MISSOVER DSD; INPUT (KEY PROC1-PROC3) ($); DATALINES; 1A, SQL, GBAR, FREQ 1A, , , MEANS 1A, , APPEND 2B, , , APPEND 3C, COMPARE, SHEWHART, PWENCODE 3C, IML 4D, , APPEND 4D, APPEND, GLM, REG 5E, SQL 5E, , GPLOT ; RUN; I want to generate a macro variable containing all the distinct values of KEY where one of the PROC variables is equal to APPEND. This PROC SQL code does the trick for exactly three PROC variables: %LET APPEND_KEYS = ; PROC SQL NOPRINT; SELECT DISTINCT KEY INTO:APPEND_KEYS SEPARATED BY '" "' FROM TEST WHERE FINDW(CATX(' ', PROC1, PROC2, PROC3), 'APPEND'); QUIT; %PUT "&APPEND_KEYS"; /* On the log appears "1A" "2B" "4D" */ Now suppose that I want to generalize this code to work with an arbitrary number of PROC variables on the TEST data set. I know that I can accomplish this by writing a SAS macro, but I'm hoping that there is a better way. Therefore, I'm not interested in seeing any %MACRO solutions. Here is what I've done so far using the DATA step: %LET APPEND_KEYS = ; DATA _NULL_; SET TEST; BY KEY; LENGTH ALL_PROCS $ 32767; RETAIN ALL_PROCS ' '; ALL_PROCS = CATX(' ', ALL_PROCS, CATX(' ', OF PROC:)); IF LAST.KEY THEN DO; IF FINDW(ALL_PROCS, 'APPEND') THEN CALL SYMPUTX("APPEND_KEYS", CATX('" "', RESOLVE('&APPEND_KEYS'), KEY)); CALL MISSING(ALL_PROCS); END; RUN; %PUT "&APPEND_KEYS"; /* On the log appears "1A" "2B" "4D" */ The results are the same for both the DATA step and PROC SQL, but there are some problems with the DATA step: On my actual dataset the DATA step takes much longer to execute than the PROC SQL step, probably because of the WHERE clause utilized by PROC SQL. The problem is that the CATX(' ', OF PROC:) syntax is not supported in a WHERE statement. Can anyone think of an alternate approach that would be faster? The DATA step above produces these really annoying notes in the log about the meaning of an identifier after a quoted string changing in a future release of SAS. For the sample data I provided, the note only appears once. However, using my actual data set, the note appears many times and fills up a sizable chunk of my log window. I don't understand exactly which part of my code is causing that note to appear. Thanks in advance for any ideas.
... View more