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'*/
I messed up the parentheses. Why don't you try to fix them?
Use the TRANSLATE function
%let Vector2=%sysfunc(translate,&vector1,%str( ),%str(,));
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.
I messed up the parentheses. Why don't you try to fix them?
%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2 = %sysfunc(translate(%quote(&Vector1),' ',','));
%put &Vector1;
%put &Vector2;
@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(,)));
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;
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!
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.