DATA Step, Macro, Functions and more

Drop the decimal point?

Reply
N/A
Posts: 0

Drop the decimal point?

Hi All

How do I drop the decimal point in the numeric value e.g. 10560.00 should be output as 1056000?

Thanks!
Frequent Contributor
Posts: 102

Re: Drop the decimal point?

Posted in reply to deleted_user
Shelton,

We will need a little more information. In what situation do you want to hide the decimal point? For most situations you will want to create a format for the variable to something like:


proc format ;
picture nodec
low - high = '0000000' (MULTIPLIER=100 ) ;
run;


data junk;
x = 10560.00;
format x nodec.;
put x;
run;
N/A
Posts: 0

Re: Drop the decimal point?

Posted in reply to CurtisMack
Well the output format should look like this:

002319122+

From a value of $23191.22

The above format is required by another process - not sure why they want it like this.

This is my current DATA step:
DATA SENDIT;
SET ONE;
INVAMNTS=PUT(INVAMNT,9.);

FILE BWOUTPT;
PUT @001 CCODE $2. /*BRANCH-CODE*/
@003 DOCREF $6.
@009 SERIAL $17.
@026 STDTE $8. /*RETAIL-SOLD-DATE*/
@034 DEALER $4. /*ACCOUNT-NO*/
@038 CONIND $1. /*ON-CONSIGNMENT-IND*/
@039 INVDTE $8. /*BILLING-DATE*/
@047 BILLNO $9. /*INVOICE-NUMBER*/
@055 GRDATE $8. /*RECEIPT-DATE*/
@065 INVAMNTS $12. /*INVOICE-AMOUNT*/
;

Thanks for your help
Shelton.

Message was edited by: shelton Message was edited by: shelton
N/A
Posts: 0

Re: Drop the decimal point?

Posted in reply to deleted_user
I Tried what you suggested Curtis, but in the output the 00 at the end is dropped off:

*********
686
686
4251
686
686
686
20
687
7085
6660
6912
9624
920
10560
12000
5095
7390
10560
10191
Frequent Contributor
Posts: 102

Re: Drop the decimal point?

Posted in reply to deleted_user
Shelton,

Since you didn't show the code that generated this, I don't know exactly what went wrong here, but I suspect you weren't seeing the zeros truncated, but instead the values were left justified. Try this:

-----------------------------------------------
proc format ;
picture nodec
low - high = '00000000' (MULTIPLIER=100 ) ;
run;

data junk;
x = 10560.00; output;
x = 60.01; output;
x = 100.10; output;
run;

data _null_;
set junk;
file "c:\temp\junk.txt";
put x nodec.;
run;

------------------------------------
This is what I got (it lines up correctly in a fixed width font)
----------------------------------
1056000
6001
10010
---------------------------------

Curtis
Frequent Contributor
Posts: 102

Re: Drop the decimal point?

Posted in reply to deleted_user
Assuming that + sign is supposed to represent the sign of the value you can just play with the picture format a bit to get this result. Something like one of these, depending on how you need leading zeros:
----------------------------------------------------

proc format ;
picture nodec
low - -0.0000001 = '00000009-' (MULTIPLIER=100 )
0 - high = '00000009+' (MULTIPLIER=100 ) ;
run;

proc format ;
picture nodec
low - -0.0000001 = '00000999-' (MULTIPLIER=100 )
0 - high = '00000999+' (MULTIPLIER=100 ) ;
run;
-----------------------------------------------------
Curtis
Frequent Contributor
Posts: 102

Re: Drop the decimal point?

Posted in reply to CurtisMack
I think this is closer to what you need:
-------------------------------------------
proc format ;
picture nodec
low - -0.0000001 = '99999999999-' (MULTIPLIER=100 )
0 - high = '99999999999+' (MULTIPLIER=100 ) ;
run;
-----------------------------------------
Of course, this all assumes your variable is a numeric. If not, I don't think there is a way to do this without first converting it to one. Something like this would work;

--------------------------------------
data _null_;
x = "0092929.00";
x = put(input(x,10.2),nodec.);
put x;
run;
-------------------------------------------

Curtis
N/A
Posts: 0

Re: Drop the decimal point?

Posted in reply to CurtisMack
Hi Curtis

It seems to work - however I have one small problem:

The output is 12 char long, I need it to be 10 char long, starting at position column 65 - this is the current output:

+----7----+-------
****************
00000000686+

This is the code:

PROC FORMAT ;
PICTURE NODEC
LOW - -0.0000001 = '99999999999+' (MULTIPLIER=100 )
0 - HIGH = '99999999999+' (MULTIPLIER=100 ) ;
RUN;

DATA SENDIT;
SET ONE;
X = PUT(INPUT(INVAMNT,12.2),NODEC.);
PLUSSIGN ="+";
FILE BWOUTPT;
PUT @001 CCODE $2. /*BRANCH-CODE*/
@003 DOCREF $6.
@009 SERIAL $17.
@026 STDTE $8. /*RETAIL-SOLD-DATE*/
@034 DEALER $4. /*ACCOUNT-NO*/
@038 CONIND $1. /*ON-CONSIGNMENT-IND*/
@039 INVDTE $8. /*BILLING-DATE*/
@047 BILLNO $9. /*INVOICE-NUMBER*/
@055 GRDATE $8. /*RECEIPT-DATE*/
@065 X $12. /*INVOICE-AMOUNT*/
; Message was edited by: shelton
N/A
Posts: 0

Re: Drop the decimal point?

Posted in reply to deleted_user
Hi Curtis

I got it to print out 10 Char long! - I changed the input to be 10 long - thankyou very much for your help. Looks like what I wanted - now I need the other party to check it.

Thanks again!

Cheers
Shelton.
N/A
Posts: 0

Re: Drop the decimal point?

Posted in reply to deleted_user
Curtis

Can you please explain what the PICTURE function does? I have never come across this before.

Thanks
Shelton.
Frequent Contributor
Posts: 102

Re: Drop the decimal point?

Posted in reply to deleted_user
Shelton,
A quick web search will give you several good papers on the subject, so I am not going to attempt explain the syntax here. In short picture formats are just another way of creating user defined formats, only instead of them being based on mapping indvidual values or ranges of values to a particular value, they instruct SAS on how to display a numeric value with several features that are vary usefull for dates. For non-dates, they are much like numeric to string conversion formats in other languages like C#.

For example when you had the trouble with the 12 character strings, if you had just taken a few of the 9s out of the picture format, it would have returned fewer characters. If you changed those 9s to 0s, you would not see left zero fills.

If you don't have a good grasp on SAS formats, it would be well worth you time to read up on the subject. They are one of the more powerfull features of SAS.

Good Luck!
Curtis
Frequent Contributor
Posts: 102

Re: Drop the decimal point?

Posted in reply to CurtisMack
BTW, I just noticed that you changed the negative sign I had in the format for negative values to a +. I don't know what your specs are, but if you have any negative amounts, you are going to get very misleading output because they will end with a +.
N/A
Posts: 0

Re: Drop the decimal point?

Posted in reply to CurtisMack
hI Curtis

Thanks for that - just noticed my error with the negative value. I have changed it accordingly.

I will read up on the PROC FORMAT function.

Thanks for your help again - appreciate it!

Cheers
Shelton.
Ask a Question
Discussion stats
  • 12 replies
  • 337 views
  • 0 likes
  • 2 in conversation