View previous topic :: View next topic
|
Author |
Message |
mambopras
New User
Joined: 11 Nov 2008 Posts: 52 Location: Hyderabad
|
|
|
|
Hi,
I have a requirement in SAS to read a variable which is a zonal decimal of ZD14.2 and put it in the output as a numeric which can be a max of 9 digits (including decimal if any)
Example - if the value in the input file is
00000002130}00000
I need i is 213.00 or just 213 (with a leading sign if negative).
I have been trying SAS formats but was not successful. Can anyone please help me with this ? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Okay, you tell us you have a ZD14.2 SAS value, give us 17 digits, and the value is stored in just the first 12 digits -- obvious due to the sign overlay in the 12th position. I think your first, and most obvious problem, is that YOU HAVE NO IDEA WHAT YOU ARE DOING!
Assuming you really meant 12.2 and not 14.2, why not
Code: |
INPUT ... NUMVAR 12.2 ... ;
.
.
.
PUT ... NUMVAR 9.2 ; |
to output a 9-digit number with 2 decimal places maximum. If the value is greater than 999,999,999 then you'll get a BEST9. format out of SAS, but that is what you expected, right? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Your subject also makes no sense.
Zoned decimal, packed decimal, pure binary (aka binary), and a few others are all numeric, just coded differently. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Why do you believe that 00000002130}00000 is a zonal decimal of ZD14.2
This part of the value 00000002130} meets the rules for a signed, zoned decimal with a value of 213.00.
Suggest you review what you actually "have" and what you want to do with this. Hint: how is the output value to be used? |
|
Back to top |
|
|
mambopras
New User
Joined: 11 Nov 2008 Posts: 52 Location: Hyderabad
|
|
|
|
Well, apologies for my earlier 'not properly' framed question and confusion over terminology.
Requirement :I have an existing SAS program in production that reads an amount field having values like 0000000002130{ from an input file into a variable of ZD14.2. This variable wasn't moved to the out put field earlier. Now, I need to move it into the output such that it gets displayed as 213.00 (Truncating the leading zeros). I tried using NO DOLLAR9.2 etc...but could not get the amount displayed as required.
So what should be the declaration of the variable in the PUT statement was the question I intended to ask - But I couldn't convey that earlier.
The output is used as a report. However, we couldn't use PROC PRINT (which could have taken care of this issue) to generate report as our requirements made us code everything manually due to the extra customization the client wanted.
I hope this explanation is better than the earlier. Can you help me out with this ? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Try looking up COMMA or D in the manual, see if either give you what you want. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
put @x value 14.2; |
|
Back to top |
|
|
mambopras
New User
Joined: 11 Nov 2008 Posts: 52 Location: Hyderabad
|
|
|
|
Peter I tried that way but the leading zeros are not being truncated.
Bill : I tried a NO DOLLAR14.2. It seems to work ok. I would have to do more testing.
Thanks a lot to all of you for your responses and help. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
And this one ? :
char=put(value,14.2); |
|
Back to top |
|
|
mambopras
New User
Joined: 11 Nov 2008 Posts: 52 Location: Hyderabad
|
|
|
|
Peter, I need to try this!!! |
|
Back to top |
|
|
|