LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (January 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 7 Jan 2005 10:23:01 -0500
Reply-To:   Jonas Bilenas <Jonas.Bilenas@CHASE.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jonas Bilenas <Jonas.Bilenas@CHASE.COM>
Subject:   Re: macro loop vs datastep loop

PROC FORMAT is the way to go:

proc format; value $drug 'L' = 'Ldrug' 'M' = 'Mdrug' 'X' = 'Xdrug' ;

Then use a format statement in a PROC. IE:

proc freq data=x; table v; format v $drug.; run;

Or using a put statement in a datastep:

data y; set x; drug = put(v,$drug.); run;

Jonas Bilenas

On Fri, 7 Jan 2005 04:09:54 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:

>Ben, > >Look into proc format, it should solve your problem in a very simple way. > > > >Toby Dunn > > > > >From: Ben <benpub7@YAHOO.COM> >Reply-To: Ben <benpub7@YAHOO.COM> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: macro loop vs datastep loop >Date: Thu, 6 Jan 2005 20:22:09 -0500 >I am sorry, david, this example is not good. >drugs are supposed to be variables, we could not know it before program >runnning. I have an solution, but I 'd like to know if there is another >cooler solution. > >*************************; >data x; >input v $ @@; >datalines; >L M M X >; >run; > > >%let vlst=Mdrug1 Ldrug2 Xdrug3; > >%macro x; >proc datasets; >delete _:; >run; > >%let i=1; >%do %until (%scan(&vlst,&i,' ')=); >%let v=%scan(&vlst,&i, ' '); > >data _x&i; >set x; >if upcase(v)="%substr(&v,1,1)" then new_v="&v"; >if length(new_v)>1; >run; > >proc append base=_newx data=_x&i; >run; >%let i=%eval(&i+1); >%end; >%mend x; > >%x; > >data x; >set _newx; >run; > >**************************; > > >On Thu, 6 Jan 2005 16:52:39 -0800, David L. Cassell ><cassell.david@EPAMAIL.EPA.GOV> wrote: > > >Ben <benpub7@YAHOO.COM> wrote: > >> data x; > >> input v $ @@ ; > >> datalines; > >> L M M X > >> ; > >> run; > >> > >> How could I translate L to Ldrug, M to Mdrug , X to Xdrug? > > > >Okay, I don't think you need a loop of any sort - other than > >the implicit loop in a DATA step. You have read in the data > >so that each value of V is in a separate record, instead of > >trying to shove them all as different variables in a single > >record. Good! > > > >So all you need to do (if I understand what you want) is to > >append the letters 'drug' onto the end of each value of V. > >That's straight forward: > > > > > >data temp2; > > set x; > > v = trim(v)||'drug'; > > run; > > > >proc print noobs; run; > > > > > >Why do I have that TRIM() in there? Well, you read in your > >values of V without telling SAS anything other than that they are > >character. So they got a default length of 8. (Check out a PROC > >CONTENTS of your data set above to see this.) That means that the > >values look like a single letter, followed by 7 blanks. If you > >try to concatenate anything onto that, you'll have the single letter, > >then 7 blanks, then new stuff.. which has to be truncated to fit in > >the width of 8, so all the new stuff gets lost. Try it yourself > >without the TRIM() part in there. > > > >HTH, > >David > >-- > >David Cassell, CSC > >Cassell.David@epa.gov > >Senior computing specialist > >mathematical statistician


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