DATA Step, Macro, Functions and more

Add space between two variable values

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

Add space between two variable values

[ Edited ]

I have a syntax like below. I what to add a space between two variable. Please help me on this

text2 = cats('"/user/path`',&year,put(lastmonth,nlstrmon.),'filename.txt','"');

for example I am expecting a output like below

 

"/user/path/2016 AUGUST filename.txt"


Accepted Solutions
Solution
‎09-02-2016 09:43 AM
Respected Advisor
Posts: 3,124

Re: Add space between two variable values

Might resort to the old school way:

%let year=2016;
data test;
lastmonth=8;
text2 = cats('"/user/path/',&year,' ',put(lastmonth,nlstrmon.),'filename.txt','"');
text_want='"/user/path/'||strip(&year)||' '||put(lastmonth,nlstrmon.)||' '||'filename.txt'||'"';
run;

View solution in original post


All Replies
Super User
Posts: 17,907

Re: Add space between two variable values

[ Edited ]

Add a space before filename.txt?

Otherwise switch from the CATS() function to a different version of the CAT family of functions that honours spaces. 

You can use the || operator as well. 

 

Edit: CATT trims trailing blanks, but keeps leading blanks. 

Solution
‎09-02-2016 09:43 AM
Respected Advisor
Posts: 3,124

Re: Add space between two variable values

Might resort to the old school way:

%let year=2016;
data test;
lastmonth=8;
text2 = cats('"/user/path/',&year,' ',put(lastmonth,nlstrmon.),'filename.txt','"');
text_want='"/user/path/'||strip(&year)||' '||put(lastmonth,nlstrmon.)||' '||'filename.txt'||'"';
run;
Contributor
Posts: 55

Re: Add space between two variable values

Thanks a lot. It works great

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 220 views
  • 0 likes
  • 3 in conversation