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 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 6 Jan 2005 16:52:39 -0800
Reply-To:     cassell.david@EPAMAIL.EPA.GOV
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject:      Re: macro loop vs datastep loop
In-Reply-To:  <200501062220.j06MKghp016324@listserv.cc.uga.edu>
Content-type: text/plain; charset=US-ASCII

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