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 (February 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 23 Feb 2008 11:30:22 +0100
Reply-To:     Stefan Pohl <stefan.pohl@ISH.DE>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Stefan Pohl <stefan.pohl@ISH.DE>
Subject:      problem in macro programming
Comments: cc: "Howard Schreier <hs AT dc-sug DOT org>"
          <schreier.junk.mail@GMAIL.COM>
In-Reply-To:  <200802230036.m1MNKPKv021898@mailgw.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

Dear SAS-group,

> >> > within a macro I want to transform a numerical id in a character id. > >> > Normally you write idChar=PUT(id,4.); if your biggest id is for > >> > example 1208. > >> > I want to generalize the 4. information as it depends on my data set.

> The BEST3. format should work well with positive integers up > to and including 999. So what is meant by "does not work"? > Please post test data and runnable code along with the explanation.

Here is a test macro and a test data set. You will find indise the macro code my comments.

%MACRO test(data,id);

PROC MEANS DATA=&data NOPRINT; VAR &id; OUTPUT OUT = idmax_&data max=maxid; RUN;

DATA digits_&data (DROP = maxid); SET idmax_&data (obs=1 keep=maxid); digits = int(log10(maxid))+1; RUN;

DATA _null_; SET digits_&data; call symputx("digits",Length(Strip(digits))); *stop; RUN;

DATA &data.1 (DROP=&id RENAME=(idChar=&id)); SET &data; LENGTH idChar $10000.;

*idChar=PUT(&id,2.); * This works well; idChar=PUT(&id,Best&digits..); * Alternatively, this way not. Why???;

RUN;

%MEND test;

DATA test; INPUT id; CARDS; 1 2 3 4 5 6 7 8 9 10 11 12 ; RUN;

%test(test,id)

Best wishes, Stefan.


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