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 (May 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 22 May 2009 17:09:32 -0400
Reply-To:     msz03@albany.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Mike Zdeb <msz03@ALBANY.EDU>
Subject:      Re: Convert numeric to character,
              but don't know the length of the numeric variable.
Content-Type: text/plain;charset=iso-8859-1

hi ... so, here's another idea ...

* make some data; data old; do j=1 to 1e5; x = ceil(1000000*ranuni(99)); if ranuni(99) le .001 then output; end; drop j; run;

* find the length of the largest number; proc sql noprint; select length(cat(max(x))) into :longest from old; quit;

* create character variables ... A is left-justified, B is right-justified, your choice; data new; length a b $&longest; set old; a = cat(x); b = right(cat(x)); run;

* take a look; proc contents data=new; ods select variables; run;

proc print data=new; run; -- Mike Zdeb U@Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475

> Hi all, > > I want to convert a numeric variable (e.g., 1560) to a character variable, I can use put (num,4.0) to nake a $4 variable, but if I have 156, that > would create an extra space in the character variable, is there anyway that I can use to find the number of digit in the numeric variable and > convert it using corresponding format? > > Thanks. > > > > _________________________________________________________________ > Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! > http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us >


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