BookmarkSubscribeRSS Feed
Macro
Obsidian | Level 7

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?

4 REPLIES 4
Reeza
Super User

add a space to your macro variable?

Macro
Obsidian | Level 7

It did not work though. How?

stat_sas
Ammonite | Level 13

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

%put my_format=&my_format;

Loko
Barite | Level 11

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)

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1120 views
  • 0 likes
  • 4 in conversation