|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:
value $drug 'L' = 'Ldrug'
'M' = 'Mdrug'
'X' = 'Xdrug'
Then use a format statement in a PROC. IE:
proc freq data=x;
format v $drug.;
Or using a put statement in a datastep:
drug = put(v,$drug.);
On Fri, 7 Jan 2005 04:09:54 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Look into proc format, it should solve your problem in a very simple way.
>From: Ben <benpub7@YAHOO.COM>
>Reply-To: Ben <benpub7@YAHOO.COM>
>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
>input v $ @@;
>L M M X
>%let vlst=Mdrug1 Ldrug2 Xdrug3;
>%do %until (%scan(&vlst,&i,' ')=);
>%let v=%scan(&vlst,&i, ' ');
>if upcase(v)="%substr(&v,1,1)" then new_v="&v";
>proc append base=_newx data=_x&i;
>On Thu, 6 Jan 2005 16:52:39 -0800, David L. Cassell
> >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.
> >David Cassell, CSC
> >Senior computing specialist
> >mathematical statistician