A follow-up to: https://communities.sas.com/t5/SAS-Programming/let-list-quot-X-quot-gt-Literal-Contains-Unmatched-Quote/td-p/585064 The arrays (not_done_list, col_list, query_list, sas_check) are all aligned so that the same indexed value corresponds with each other. %let not_done_list = SODIUMND | SODIUMND; /*column names (ND=NOT DONE) */
%let col_list = SODIUM | SODIUM ; /*column names */
/* query_list and sas_check are just strings in array, not column names */ %let query_list= 'querytext1' | 'querytext2' ;
%let sas_check = "CHEM005" | "CHEM006";
%macro create_table(not_done_list, col_list, query_list, sas_check);
proc sql noprint;
CREATE TABLE t1 AS
SELECT DISTINCT %str(&query_list) as query_text, %str(&sas_check) as SAS_Check, Subject, %str(¬_done_list) as not_done_list, %str(&col_list) as col_list
FROM chem
GROUP BY Subject
HAVING ((put(&col_list, best.)^="" or put(&col_list, best.)="No") and not_done_list IS NOT NULL) OR
((put(col_list, best.)="" or put(&col_list, best.)="Yes") and not_done_list IS NOT NULL)
;
quit;
%mend create_table;
%macro prep_table(notdone, col, query, sas_check );
%local item;
%do item=1 %to %sysfunc(countw(¬_done_list));
%let notdone=%scan(¬_done_list,&item);
%let col=%scan(&col_list,&item);
%let query=%scan(&query_list,&item, |);
%let sas=%scan(&sas_check,&item, |);
%create_table(not_done_list=¬done, col_list=&col, query_list=&query, sas_check=&sas);
%end;
%mend prep_table;
%prep_table(notdone=¬_done_list, col=&col_list, query=&query_list, sas_check=&sas_check ); Example Input: ╔═════════╦══════════╦════════╗
║ Subject ║ SODIUMND ║ SODIUM ║
╠═════════╬══════════╬════════╣
║ 001 ║ No ║ ║
║ 001 ║ Yes ║ ║
║ 002 ║ Yes ║ 221 ║
║ 002 ║ No ║ ║
╚═════════╩══════════╩════════╝ No error log, but (not expected) Output: ╔════════════╦═══════════╦═════════╦═══════════════╦══════════╗
║ query_text ║ SAS_Check ║ Subject ║ not_done_list ║ col_list ║
╠════════════╬═══════════╬═════════╬═══════════════╬══════════╣
║ querytext1 ║ CHEM005 ║ 001 ║ No ║ ║
║ querytext1 ║ CHEM005 ║ 002 ║ Yes ║ 221 ║
║ querytext1 ║ CHEM005 ║ 002 ║ No ║ ║
╚════════════╩═══════════╩═════════╩═══════════════╩══════════╝ What's wrong: 1. Only querytext1 is outputted (there is dirty data for querytext2, but no output). 2. SAS_Check isn't right, it should be the corresponding SAS_Check via the same index in all the arrays. 3. not_done_list and col_list should be the value as a string Expected output: ╔════════════╦═══════════╦═════════╦══════════╦════════╗
║ query_text ║ SAS_Check ║ Subject ║ SODIUMND ║ SODIUM ║
╠════════════╬═══════════╬═════════╬══════════╬════════╣
║ querytext1 ║ CHEM005 ║ 001 ║ No ║ ║
║ querytext1 ║ CHEM005 ║ 002 ║ Yes ║ 221 ║
║ querytext2 ║ CHEM006 ║ 002 ║ No ║ ║
╚════════════╩═══════════╩═════════╩══════════╩════════╝ So, if there's a third, different column name in not_done_list and col_list, then it would be like ╔════════════╦═══════════╦═════════╦══════════╦════════╦═════════╦═══════╗
║ query_text ║ SAS_Check ║ Subject ║ SODIUMND ║ SODIUM ║ thirdND ║ third ║
╠════════════╬═══════════╬═════════╬══════════╬════════╬═════════╬═══════╣
║ querytext1 ║ CHEM005 ║ 001 ║ No ║ ║ ║ ║
║ querytext1 ║ CHEM005 ║ 002 ║ Yes ║ 221 ║ ║ ║
║ querytext2 ║ CHEM006 ║ 002 ║ No ║ ║ ║ ║
╚════════════╩═══════════╩═════════╩══════════╩════════╩═════════╩═══════╝ I know this is a lot to ask, but I'm just stuck. Thanks
... View more