BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASSLICK001
Obsidian | Level 7

Hi All 

 

I am trying to create a macro variable with value formed by concatenate symbol ("+" ) to a text string.

for example i need to create the following, attaching "+" based on iterations (4 times) and store it in a macro variable.

 

"test++++" 

 

Thanks for all the help.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You mean this ?

 

%macro x;
%let x=test;
%do i=1 %to 3;
  %let x=&x+;
%end;

%put &x;
%mend;

%x 

View solution in original post

4 REPLIES 4
LaurieF
Barite | Level 11

Is what you want as simple as this?

 

%let macvar = test%sysfunc(repeat(+, 3));
%put &=macvar;

 

The repeat function takes the first parameter and repeats it n times.

Criptic
Lapis Lazuli | Level 10

Here a coding example if you want to do it inside of a data step:

data _null_;
	length combined $50.;
	base = "Hello";
	combined = cat(base,repeat("+",3));
	call symput("plusString",combined);
run;

%put &plusString;
Jagadishkatam
Amethyst | Level 16
I like the approach of @Laurie F, Here is an alternate approach

%let macvar = %sysfunc(cats(test,+++));
%put &=macvar;
Thanks,
Jag
Ksharp
Super User

You mean this ?

 

%macro x;
%let x=test;
%do i=1 %to 3;
  %let x=&x+;
%end;

%put &x;
%mend;

%x 

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
  • 3939 views
  • 3 likes
  • 5 in conversation