LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 5 Sep 2011 03:44:09 -0400
Reply-To:     Søren Lassen <s.lassen@POST.TELE.DK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Søren Lassen <s.lassen@POST.TELE.DK>
Subject:      Re: Replacing blanks using Tranwrd
Comments: To: Craig Johnson <cjohns38@GMAIL.COM>
Content-Type: text/plain; charset=ISO-8859-1

Craig, The easiest way is to use COMPBL to get rid of multiple blanks before TRANWRD. I would put in code to ret rid of blanks before and after "*", though (I assume that you are parsing macro parameters - allowing blanks before and after the "*" operators seems the most natural): %LET ALLOW_TO_DROP= Age_C53*Factor1 Age_C53*Factor2 Age_c53*sex2 Age_C53*Age_C53*Sex2 Age_C53*Age_C53*Factor1 Age_C53*Age_C53*Factor2 sex2*Factor1 sex2*Factor2 Sex2*Factor1*Age_c53 Sex2*Factor2*Age_c53; /* Get rid of multiple blanks */ %let allow_to_drop2=%sysfunc(compbl(&allow_to_drop)); /* Get rid of blanks before asterisks */ %let allow_to_drop2=%sysfunc(tranwrd(&allow_to_drop2,%str( *),*)); /* Get rid of blanks after asterisks */ %let allow_to_drop2=%sysfunc(tranwrd(&allow_to_drop2,%str(* ),*)); /* Convert remaining blanks to slashes */ %let allow_to_drop2=%sysfunc(tranwrd(&allow_to_drop2,%str( ),/)); %put &allow_to_drop2;

It is possible to write the whole shebang as a single, nested function call - but with all the %SYSFUNCs included, that would make the code virtually unreadable.

Your original aim (just using the first and the last function calls) may look kind of OK as a nested function call:

%let allow_to_drop2= %sysfunc(tranwrd(%sysfunc(compbl(&allow_to_drop)),%str( ),/));

Regards, Søren

On Fri, 2 Sep 2011 15:17:34 -0500, Craig J <cjohns38@GMAIL.COM> wrote:

>Building a macro up and I'm going to need convert blanks with a character >separator. > >Example: >%LET ALLOW_TO_DROP= Age_C53*Factor1 > Age_C53*Factor2 > Age_c53*sex2 > Age_C53*Age_C53*Sex2 > Age_C53*Age_C53*Factor1 > Age_C53*Age_C53*Factor2 > sex2*Factor1 > sex2*Factor2 > Sex2*Factor1*Age_c53 > Sex2*Factor2*Age_c53; >%LET ALLOW_TO_DROP2= %SYSFUNC(TRANWRD(&ALLOW_TO_DROP," ", /)); > >%PUT &ALlow_To_Drop2; > > >What I want the output to look like > >Age_C53*Factor1/ >Age_C53*Factor2/Age_c53*sex2/Age_C53*Age_C53*Sex2/Age_C53*Age_C53*Factor1/A ge_C53*Age_C53*Factor2/ >sex2*Factor1/sex2*Factor2/Sex2*Factor1*Age_c53/Sex2*Factor2*Age_c53/ > >Output I'm getting isn't replacing the blanks and I'm not sure what I'm >doing wrong. > >Thoughts?


Back to: Top of message | Previous page | Main SAS-L page