BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lyudmilpetrov
Calcite | Level 5

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,

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
tsap
Pyrite | Level 9

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.

 

View solution in original post

4 REPLIES 4
tsap
Pyrite | Level 9

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.

 

lyudmilpetrov
Calcite | Level 5
Thanks a lot very clear explanation almost accepted without testing, but test and perfect.

Much appreciated and all the best,

Lyudmil
lyudmilpetrov
Calcite | Level 5

Thank you so much for the perfect input, it works as charm.

 

All the best,

 

Lyudmil

tsap
Pyrite | Level 9
Glad I could help!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1005 views
  • 0 likes
  • 2 in conversation