BookmarkSubscribeRSS Feed
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 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*/
7 REPLIES 7
tarheel13
Rhodochrosite | Level 12

well we just showed you how to remove spaces in your other post.

Ronein
Onyx | Level 15

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

Ronein
Onyx | Level 15

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.
yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



tarheel13
Rhodochrosite | Level 12

you need to wrap &vector1 with %quote().

%let Vector1='RFA07','RFA02','RFA04','BRG92','PER1903';
%let Vector2 = %qsysfunc(compress(%quote(&vector1),%str(%')));
%put &=vector2;
tarheel13
Rhodochrosite | Level 12

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;
PaigeMiller
Diamond | Level 26
%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

--
Paige Miller
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
  • 7 replies
  • 1811 views
  • 1 like
  • 4 in conversation