Dear experts,
I have a simple request to create variable in SAS Stored process and concatenate two strings one is coming from GLOBAL variable / prompt / input
and the other is static.
Where &user is Global input.
If I run the stored process and enter into the prompt for user variable the info:
ABCD
data _null_;
call symputx('end_table_1', &user || '_end_1');
run;
%put &user;
%put &end_table_1;
I will see as result printed out
36 +%put &USER;
ABCD
37 +%put &end_table_1;
._end_1
which the dot tells me that $user is not visible in (call symputx), but how come is visible for %put.
But if that run separately as program it executes fine:
%let user = 'test';
data _null_;
call symputx('end_table_1', &user. || '_end_1');
run;%put &USER;
%put &end_table_1;
Result
33 %put &USER;
'test'
34 %put &end_table_1;
test_end_1
Much appreciated any help,
The problem is related to this line of logic:
call symputx('end_table_1', &user || '_end_1');
When &user resolves the line becomes this:
call symputx('end_table_1', ABCD || '_end_1');
So it thinks that there is a variable called ABCD and attempts to populate with a value from that variable. So you end up getting that weird macro resolution.
Now when you ran the code and used 'test' as the value of &user, you included the quotes in the resolved value of the macro.
So that time the line would appear as this:
call symputx('end_table_1', 'test' || '_end_1');
So SAS knew that test was a literal text string and concatenated with the other literal text string and your final macro resolved appropriately.
Simplest solution - Put double quotation marks around your &user macro in the Call Symputx statement.
Example:
data _null_;
call symputx('end_table_1', "&user" || '_end_1');
run;
That should solve your problem. the macro will resolve within the double quotes (not within single quotes), and the quotation marks will remain, letting SAS know that ABCD is a literal string and not a variable name.
Hope this helps.
The problem is related to this line of logic:
call symputx('end_table_1', &user || '_end_1');
When &user resolves the line becomes this:
call symputx('end_table_1', ABCD || '_end_1');
So it thinks that there is a variable called ABCD and attempts to populate with a value from that variable. So you end up getting that weird macro resolution.
Now when you ran the code and used 'test' as the value of &user, you included the quotes in the resolved value of the macro.
So that time the line would appear as this:
call symputx('end_table_1', 'test' || '_end_1');
So SAS knew that test was a literal text string and concatenated with the other literal text string and your final macro resolved appropriately.
Simplest solution - Put double quotation marks around your &user macro in the Call Symputx statement.
Example:
data _null_;
call symputx('end_table_1', "&user" || '_end_1');
run;
That should solve your problem. the macro will resolve within the double quotes (not within single quotes), and the quotation marks will remain, letting SAS know that ABCD is a literal string and not a variable name.
Hope this helps.
Thank you so much for the perfect input, it works as charm.
All the best,
Lyudmil
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.