I’ve a multiline text prompt is SAS.
I tried to create a macro to convert all lines from the multiline text prompt into a single text line with all the values single quoted and comma separated. Like 'ID_1', 'ID_2', 'ID_3'
.
I need to use the new variable P_ID
from the macro in a SQL query IN statement.
What i’ve tried so far:
<code>%MACRO to_single_line;
%GLOBAL P_ID;
%DO i = 1 %TO &multiline_COUNT;
%IF &i = 1 %THEN
%LET P_ID = %STR(%')&multiline%STR(%');
%ELSE %LET P_ID = &P_ID, %STR(%')&multiline&i%STR(%');
%END;
%MEND;
%to_single_line;
</code>
<code>%MACRO to_single_line;
%GLOBAL P_ID;
%DO i = 1 %TO &multiline_COUNT;
%IF &i = 1 %THEN
%LET P_ID = %STR(%')&multiline%STR(%');
%ELSE %LET P_ID = &P_ID, %STR(%')&multiline&i%STR(%');
%END;
%MEND;
%to_single_line;
</code>
%MACRO to_single_line;
%GLOBAL P_ID;
%DO i = 1 %TO &multiline_COUNT;
%IF &i = 1 %THEN
%LET P_ID = %STR(%')&multiline%STR(%');
%ELSE %LET P_ID = &P_ID, %STR(%')&multiline&i%STR(%');
%END;
%MEND;
%to_single_line;
Error:
<code>ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&multiline_COUNT
ERROR: The %TO value of the %DO I loop is invalid.
</code>
<code>ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&multiline_COUNT
ERROR: The %TO value of the %DO I loop is invalid.
</code>
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&multiline_COUNT
ERROR: The %TO value of the %DO I loop is invalid.
Any help much appriciated.