CALL SYMPT: concatenation of single quote

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

CALL SYMPT: concatenation of single quote

Hi,


 


I need to concatenate some variable, text and single quote in a CALL SYMPT istruction.


 


I tried


 


<SPAN style="FONT-SIZE: 8pt" mcestyle="font-size: 8pt;">

call symput('log_file_name', '''' || &logdir || '/' || nomefile || "'");




 


 


but it does not work.


<SPAN style="FONT-SIZE: 8pt" mcestyle="font-size: 8pt;">


Basically I have to


 










 


 
























































































Accepted Solutions
Solution
‎12-20-2011 10:02 AM
Super User
Super User
Posts: 7,039

Re: CALL SYMPT: concatenation of single quote

I think you are one the right track, you just need to experiment a little to see what you get.

call symput('log_file_name', '''' || &logdir || '/' || nomefile || ''''); (four or three single quote)

Probably the macro variable LOGDIR is a string and not the name of a dataset variable.  If so you need to put in it double quotes so that the resulting SAS statement is valid.

Same with nomefile.  Is that the name of a dataset variable.  (is it a typo for namefile?).

Usually with this type of concatenation you want to remove the trailing spaces on the value of the variable using trim() function.

Try something like:

call symputx('log_file_name', "'" || "&logdir" || '/' || trim(nomefile) || "'"); 

If it runs without syntax errors you can test it by putting a %PUT &LOG_FILE_NAME;  statement after the data step .

View solution in original post


All Replies
Contributor
Posts: 58

CALL SYMPT: concatenation of single quote

Sorry, some trouble with ie.

Here you are the question.

Hi,

I need to concatenate some variable, text and single quote in a CALL SYMPT istruction.

I tried

call symput('log_file_name', '''' || &logdir || '/' || nomefile || ''''); (four or three single quote)

and

call symput('log_file_name', '''' || &logdir || '/' || nomefile || "'"); (a double qoute with a single quote inside)


but they do not work.

Basically I have to add a single quote at the beginning and at the end of the concatenation.

Any suggestion will be very appreciate.

Thanks.

Solution
‎12-20-2011 10:02 AM
Super User
Super User
Posts: 7,039

Re: CALL SYMPT: concatenation of single quote

I think you are one the right track, you just need to experiment a little to see what you get.

call symput('log_file_name', '''' || &logdir || '/' || nomefile || ''''); (four or three single quote)

Probably the macro variable LOGDIR is a string and not the name of a dataset variable.  If so you need to put in it double quotes so that the resulting SAS statement is valid.

Same with nomefile.  Is that the name of a dataset variable.  (is it a typo for namefile?).

Usually with this type of concatenation you want to remove the trailing spaces on the value of the variable using trim() function.

Try something like:

call symputx('log_file_name', "'" || "&logdir" || '/' || trim(nomefile) || "'"); 

If it runs without syntax errors you can test it by putting a %PUT &LOG_FILE_NAME;  statement after the data step .

Super User
Posts: 11,343

Re: CALL SYMPT: concatenation of single quote

You don't describe what happens or errors when "they do not work" so this is a blind shot.

When developing similar constructs I generally start with a temporary string variable and assign the values to it before using CALL SYMPUT. This allows me to examine the value in a data set to see what may be going on.

length tstr $ 100; /* or other length long enough to capture expected values of concatenation*/

tstr = '''' || &logdir || '/' || nomefile || "'";

call symput ('log_file_name',tstr);

Typical problems I find in TSTR are long spaces because a variable such as nomefile is not as long as it's declared length. Typical solution is to use STRIP(NOMEFILE) or older LEFT(TRIM(NOMEFILE)).

You may also want to examine some of the other concatenation functions such as CATX or CATS for building the string.

Contributor
Posts: 58

CALL SYMPT: concatenation of single quote

call symput('log_file_name', "'" || &logdir || '/' || trim(nomefile) || "'");

works perfectly.

Thanks to Tom.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1668 views
  • 0 likes
  • 3 in conversation