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 and also the values shouldn't be quoted .
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*/
well we just showed you how to remove spaces in your other post.
True but now need to do 2 actions :
remove comma and remove quotes.
I have tried fist to remove the single quotes but I received an error
Please see the error
%let Vector1=
'RFA01',
'RFA07',
'RFA02',
'RFA03',
'RFA04',
'RFA05',
'RFB01',
'RFB02',
'RFB04',
'RFB09',
'RFB05',
'RFB06',
'RFB07',
'RFB08';
%let Vector2 = %qsysfunc(compress(&Vector1,%str(%')));
ERROR: The function COMPRESS referenced by the %SYSFUNC or %QSYSFUNC macro function has too many arguments.
Try this:
%let Vector1=
'RFA01',
'RFA07',
'RFA02',
'RFA03',
'RFA04',
'RFA05',
'RFB01',
'RFB02',
'RFB04',
'RFB09',
'RFB05',
'RFB06',
'RFB07',
'RFB08';
%let Vector2 = %qsysfunc(compress((&Vector1),%str((%'))));
%put &=Vector2.;
Bart
you need to wrap &vector1 with %quote().
%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2 = %qsysfunc(compress(%quote(&vector1),%str(%')));
%put &=vector2;
just do it in 2 steps
%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2 = %qsysfunc(compress(%quote(&vector1),%str(%')));
%let vector2 = %sysfunc(tranwrd(%quote(&vector2),%str(,),%str()));
%put &=vector2;
%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let vector2=%sysfunc(translate(%quote(&vector1),%str( ),%str(%',)));
%put &=vector1;
%put &=vector2;
The second percent sign in %str(%',) is needed to indicate to the macro processor that this is text that is a single unmatched quote. The comma following is also needed as you want to convert both single quote and comma to blanks. See https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/n09tblrxldh8k0n1kt6dkj3xlxug.htm
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.