BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

It seems SAS Macro adds a space when there is a line break as follows:

%let Sentence=The line break in this sentence
will leave a space.;

%put &Sentence;

SAS prints the following output:

1    %let Sentence=The line break in this sentence
2    will leave a space.;
3
4    %put &Sentence;
The line break in this sentence will leave a space.

Is there any way to avoid this spacing and let SAS print The line break in this sentencewill leave a space. instead? This is not a SAS example, but like % in LaTeX as follows:

\documentclass{article}

\begin{document}

The line break in this sentence
will leave a space.

However, the line break in this sentence%
won't leave a space.

\end{document}

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you want to make a long macro variable but keep the source lines short here are a couple of ways.

 

Macro code only:  Use multiple %LET statements.

%let Sentence=The line break in this sentence;
%let Sentence=&sentence.will NOT leave a space before will.;

SAS code: Use multiple string literals and CALL SYMPUTX()

data _null_;
call symputx('Sentence'
 ,'The line break in this sentence'
||'will NOT leave a space before will.'
);
run;;

Note: if you need the macro variable to contain leading and/or trailing spaces you can use the ANCIENT CALL SYMPUT() instead.

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

If you want to make a long macro variable but keep the source lines short here are a couple of ways.

 

Macro code only:  Use multiple %LET statements.

%let Sentence=The line break in this sentence;
%let Sentence=&sentence.will NOT leave a space before will.;

SAS code: Use multiple string literals and CALL SYMPUTX()

data _null_;
call symputx('Sentence'
 ,'The line break in this sentence'
||'will NOT leave a space before will.'
);
run;;

Note: if you need the macro variable to contain leading and/or trailing spaces you can use the ANCIENT CALL SYMPUT() instead.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 670 views
  • 0 likes
  • 2 in conversation