Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
mambopras

New User

Joined: 11 Nov 2008
Posts: 52

 Posted: Sat May 28, 2011 12:25 am    Post subject: converting a zonal decimal to numeric in SAS 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 ?

enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10479
Location: italy

Posted: Sat May 28, 2011 12:46 am    Post subject: Reply to: converting a zonal decimal to numeric in SAS

before posting it would be wise to review Your understanding of numeric data representation and the relative terminology
as described in
z/Architecture Principles of Operation
http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dz9zr002/CCONTENTS
here
http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/dz9zr002/8.1?DT=20030424140649

after reading You will understand why the example You posted is not a valid number
 Quote: 00000002130}00000

the sign will alway be <zone> part of the less significant digit
so the 5 zeroes to the right of the } are just garbage

https://www-304.ibm.com/support/docview.wss?uid=isg2b9de5f05a9d57819852571c500428f9a
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8344
Location: Dubuque, Iowa, USA

Posted: Sat May 28, 2011 1:05 am    Post subject:

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?
Phrzby Phil

Active Member

Joined: 31 Oct 2006
Posts: 973
Location: Richmond, Virginia

 Posted: Sat May 28, 2011 6:17 am    Post subject: Your subject also makes no sense. Zoned decimal, packed decimal, pure binary (aka binary), and a few others are all numeric, just coded differently.
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

 Posted: Sat May 28, 2011 8:08 am    Post subject: 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?
mambopras

New User

Joined: 11 Nov 2008
Posts: 52

 Posted: Sat May 28, 2011 3:16 pm    Post subject: Re: 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 ?
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Sat May 28, 2011 3:49 pm    Post subject: Try looking up COMMA or D in the manual, see if either give you what you want.
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2453
Location: Netherlands, Amstelveen

 Posted: Sat May 28, 2011 3:57 pm    Post subject: put @x value 14.2;
mambopras

New User

Joined: 11 Nov 2008
Posts: 52

 Posted: Sat May 28, 2011 4:13 pm    Post subject: 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.
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2453
Location: Netherlands, Amstelveen

 Posted: Sat May 28, 2011 4:22 pm    Post subject: And this one ? : char=put(value,14.2);
mambopras

New User

Joined: 11 Nov 2008
Posts: 52