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 (November 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Nov 2005 19:03:05 +1100
Reply-To:     Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Scott Bass <usenet739_yahoo_com_au@ALFREDO.CC.UGA.EDU>
Subject:      Re: complement of a macro variable
Comments: To: sas-l@uga.edu

Oops, to be totally precise, the line

&string;

should probably be

&string (no trailing semicolon)

Add the trailing semicolon in your calling program.

For example, with the previous macro, this code would fail with a syntax error:

data one; array stuff{*} %rename(&varlist,&varpart,b) even more vars a b c; run;

"Scott Bass" <usenet739_yahoo_com_au> wrote in message news:43687114$0$1713$5a62ac22@per-qv1-newsreader-01.iinet.net.au... > > "satya" <satyaanam@hotmail.com> wrote in message > news:1130900904.700741.269080@g47g2000cwa.googlegroups.com... >> dear sas-lers, >> here is my problem for today. >> >> i have a macro variable that list some variables: >> %let varlist=c_d_sex c_d_wei1 c_d_wei2 c_d_age1 c_d_age2 c_d_age3; >> and a corresponding macroavr that list a part of it, say; >> %let varpart=c_d_wei1 c_d_wei2; >> i want to create a third macrovar, corresponding to varlist, in which >> each single string of the complement to varpart has a different prefix >> (b instead of c) that is: >> varlist1=b_d_sex c_d_wei1 c_d_wei2 b_d_age1 b_d_age2 b_d_age3 > > Perhaps this meets your needs: > > 115 %let varlist=c_d_sex c_d_wei1 c_d_wei2 c_d_age1 c_d_age2 c_d_age3; > 116 %let varpart=c_d_wei1 c_d_wei2; > 117 > 118 %macro rename(list,exempt,prefix); > 119 %local string word; > 120 %let i=1; > 121 %let word = %scan(&list,&i,%str( )); > 122 %do %while (&word ne ); > 123 %if %index(&exempt,&word) %then > 124 %let string = &string &word; > 125 %else > 126 %let string = &string > &prefix.%substr(&word,%index(&word,%str(_))); > 127 %let i=%eval(&i+1); > 128 %let word = %scan(&list,&i,%str( )); > 129 %end; > 130 &string; > 131 %mend; > 132 > 133 options mprint; > 134 data one; > 135 array stuff{*} %rename(&varlist,&varpart,b); > MPRINT(RENAME): b_d_sex c_d_wei1 c_d_wei2 b_d_age1 b_d_age2 b_d_age3; > 136 run; > > The line: > > %let string = &string &prefix.%substr(&word,%index(&word,%str(_))); > > will find the first occurance of an underscore in the current word, and > will add the prefix to the rest of the string to the right of the > underscore (including the underscore). > >> >> Here is important to have the same order of varlist: i will use this >> macrovar to define an array in a subsequent data step and has to match >> to another similar defined array. >> >> Thanks in advance for any help >> satya >> ps i would also appreciate some links to resources, if any, that >> teaches this kind of management with macro variables > > Read the SAS Macro Language Reference. That's all I've ever read (plus > lots of practice). >


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