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

Hello

Let's say that user define a macro var called vector1 that contain values separated by comma.

The task is to create another macro variable called vector2 that contain same values as vector 1 but values separated by space

What is the way to do it please?

%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
/*Task-Create macro variable Vector2 that will be equal to
 'RFA07'   'RFA02'   'RFA04'   'BRG92'   'PER1903'*/

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I messed up the parentheses. Why don't you try to fix them?

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Use the TRANSLATE function

 

%let Vector2=%sysfunc(translate,&vector1,%str( ),%str(,));
--
Paige Miller
Ronein
Onyx | Level 15

Thanks,get error

26         %let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
27         %let Vector2=%sysfunc(translate,&vector1,%str( ),%str(,));
ERROR: Expected open parenthesis after macro function name not found.

 

PaigeMiller
Diamond | Level 26

I messed up the parentheses. Why don't you try to fix them?

--
Paige Miller
Ronein
Onyx | Level 15
%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2 = %sysfunc(translate(%quote(&Vector1),' ',','));
%put &Vector1;
%put &Vector2;
PaigeMiller
Diamond | Level 26

@Ronein wrote:
%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2 = %sysfunc(translate(%quote(&Vector1),' ',','));
%put &Vector1;
%put &Vector2;

You want the last two arguments of the TRANSLATE function to be enclosed in %str( ) and not single-quotes. While it works in this case, it may not work in other cases.

 

%let Vector2 = %sysfunc(translate(%quote(&Vector1),%str( ),%str(,)));
--
Paige Miller
tarheel13
Rhodochrosite | Level 12

Try this. 

%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2=%sysfunc(tranwrd(%quote(&vector1),%str(,),%str( )));
%put &=vector1 &=vector2;
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         %let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
 70         %let Vector2=%sysfunc(tranwrd(%quote(&vector1),%str(,),%str( )));
 71         %put &=vector1 &=vector2;
 VECTOR1='RFA07','RFA02','RFA04','BRG92','PER1903' VECTOR2='RFA07' 'RFA02' 'RFA04' 'BRG92' 'PER1903'
 72         
 73         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 6 replies
  • 1511 views
  • 0 likes
  • 3 in conversation