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 (January 2002, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 22 Jan 2002 16:29:43 +0100
Reply-To:     Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jim Groeneveld <J.Groeneveld@ITGROUPS.COM>
Subject:      Re: Deleting a word in a macro variable
Comments: To: Gunnar Petersson <gunnar.petersson@MEP.KI.SE>
Content-Type: text/plain

Dear Gunnar,

If you want to remove the 7th word for example, do:

%let ListSize = 1; %do %while (%scan(&formlist,&ListSize,%str( )) ne ); %let ListSize = %eval(&ListSize+1); %end;

%let NewList = ; %do I = 1 %to &ListSize; %if (&I ne &Word2Del) %then %let Newlist = &Newlist %scan(&Newlist,&I,%str( )); %end;

This concatenates all words, except the one to be deleted, into a new listvar. If you explicitely want spaces instead, deduce the length of the word to be deleted and append that number of spaces instead.

HTH

Regards - Jim. -- Y. (Jim) Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070 senior statistician, P.O. Box 1 fax. +31 412 407 080 senior data manager 5350 AA BERGHEM IMRO TRAMARKO: a CRO J.Groeneveld@ITGroups.com the Netherlands in clinical research

My computer has no idea what I am doing; sometimes the reverse also applies.

Notice of confidentiality: this e-mail may contain confidential information intended for the addressed recipient only. If you have received this e-mail in error please delete this e-mail and please notify the sender so that proper delivery can be arranged.

> -----Original Message----- > From: Gunnar Petersson [SMTP:gunnar.petersson@MEP.KI.SE] > Sent: Tuesday, January 22, 2002 3:10 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Deleting a word in a macro variable > > Hi, all, > > I have a macro variable loaded with all the variable types and lengths for > a > dataset transformed to for example $3 for a character variable and 8 for a > numeric variable. Now for some variables I don't want their type/length in > this string. Obviously I can't use translate or tranwrd (because there can > be lots of 8 and $3 in the string that are significant) and the only way > to > tell which to delete is to use the %scan function but how do I delete this > word (e.g put blanks instead) in the macro variable? > > An example: > > %let idvar=mlopnr; > > %LET idvarnr=%SYSFUNC(varnum(&dsid,&idvar)); > > %let formstr=$3 8 8 8 8 $24 $3; (in reality loaded by several %sysfunc) > > %let delstr=%scan(&formlist,&idvarnr,%str( )); > > If idvarnr is 7 I want to delete the last $3 from the string, but I can't > find out how to do it. > > Thanks, > > /Gunnar


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