DATA Step, Macro, Functions and more

How to create a macro var that repeat a word n times

Reply
Contributor
Posts: 50

How to create a macro var that repeat a word n times

I would like to create a macro varialbe which contains repeated '$my_p' 100 times separated by space, the output should look like $my_P $my_p $my_P

I use the following, but it is not separated by space though

%let my_format=%sysfunc(repeat($my_P ,3));

%put my_format=&my_format;

Result:

my_format=$my_P$my_P$my_P$my_P

How to make this work, and any other ways?

Super User
Posts: 19,789

Re: How to create a macro var that repeat a word n times

add a space to your macro variable?

Contributor
Posts: 50

Re: How to create a macro var that repeat a word n times

It did not work though. How?

Trusted Advisor
Posts: 1,228

Re: How to create a macro var that repeat a word n times

%let my_format=%sysfunc(repeat(%str( )$my_P ,3));

%put my_format=&my_format;

Super Contributor
Posts: 308

Re: How to create a macro var that repeat a word n times

Hello,

A macro solution:

%macro a(concvar, reptimes);

%global resvar;
%let resvar=;

%do i=1 %to &reptimes;
%let resvar=&concvar &resvar;
%end;

%mend a;


%a($my_P, 5)

Ask a Question
Discussion stats
  • 4 replies
  • 218 views
  • 0 likes
  • 4 in conversation