views:

2407

answers:

3

I have a string which looks like this:

 "ABAR_VAL", "ACQ_EXPTAX_Y",  "ACQ_EXP_TAX", "ADJ_MATHRES2"

and I'd like it to look like this:

ABAR_VAL ACQ_EXPTAX_Y ACQ_EXP_TAX ADJ_MATHRES2

ie no apostrophes or commas and single space seperated.

What is the cleanest / shortest way to do so in SAS 9.1.3 ?

preferably something along the lines of:

call symput ('MyMacroVariable',compress(????,????,????))

EDIT: just to be clear the result needs to be single space seperated, devoid of punctuation and contained in a macro variable..

+2  A: 

Is this part of an infile statement or are you indeed wanting to create macro variables that contain these values? If this is part of an infile statement you shouldn't need to do anything if you have the delimiter set properly.

infile foo DLM=',' ;

And yes, you can indeed use the compress function to remove specific characters from a character string, either in a data step or as part of a macro call.

COMPRESS(source<,characters-to-remove>)

Sample Data:

data temp;
     input a $;
datalines;
"boo" 
"123" 
"abc"
;
run;

Resolve issue in a data step (rather than create a macro variable):

data temp2; set temp;
a=compress(a,'"');
run;

Resolve issue whilst generating a macro variable:

data _null_; set temp; 
call symput('MyMacroVariable',compress(a,'"'));
run;
%put &MyMacroVariable.;

You'll have to loop through the observations in order to see the compressed values the variable for each record if you use the latter code. :)

Sassy Grrrl
this answer does not produce single space separation! However you have highlighted how to remove speechmarks which was a sticking point of mine, thanks for this..
Bazil
A: 

To compress multiple blanks into one, use compbl : http://www.technion.ac.il/docs/sas/lgref/z0214211.htm

Bongali Babu
+6  A: 

Here you go..

data test;
var1='"ABAR_VAL", "ACQ_EXPTAX_Y",  "ACQ_EXP_TAX", "ADJ_MATHRES2"';
run;

data test2;
set test;
call symput('macrovar',COMPBL( COMPRESS( var1,'",',) ) );
run;

%put &macrovar;
AFHood