format numeric with positive sign

Reply
New Contributor
Posts: 4

format numeric with positive sign

Hello,

I have to import this file txt (MOVABLE_ASSETS_STOCK.TXT):

2014/09/3080031HUF21   +0000000000027389,60+0000000000027389,59

2014/09/3080031HUF31    0000000000000000,00 0000000000000000,00

2014/09/3080031HUF32    0000000000000000,00 0000000000000000,00

2014/09/3080033HUF21   +0000000000015992,07+0000000000002021,66

2014/09/3080033HUF31   +0000000001463075,28+0000000000893020,19

2014/09/3080033HUF32   +0000000000564320,52+0000000000248261,70

This is my code:

  %let dsnnme="&path./MOVABLE_ASSETS_STOCK.TXT";

  /* Genera il dataset e lo salva nella libreria dedicata */

  data MOVABLE_ASSETS_STOCK;

  infile &dsnnme

  lrecl=400;

  informat DATA_RIF yymmdd10.;

  informat COD_ABI $5.;

  informat CURRENCY $3.;

  informat MOVABLE_CAT $5.;

  informat GBV_AMT $20.;

  informat NBV_AMT $20.;

  informat FILLER $64.;

  format DATA_RIF yymmdd10.;

  format COD_ABI $5.;

  format CURRENCY $3.;

  format MOVABLE_CAT $5.;

  format GBV_AMT $20.;

  format NBV_AMT $20.;

  format FILLER $64.;

  input DATA_RIF yymmdd10.

  COD_ABI $ 11-15

  CURRENCY $ 16-18

  MOVABLE_CAT $ 19-23

  GBV_AMT $ 24-43

  NBV_AMT $ 44-63

  FILLER $

  ;

  run;

I have a problem with GBV_AMT and NBV_AMT. In my code I have imported them with text format but this isn't correct.

I have to import them with numeric format and it must be exactly equal to file txt of input.

Could you please help me?

Thanks,

Fabio

Regular Contributor
Posts: 168

Re: format numeric with positive sign

your input statement is wrong - remove yymmdd10. and the numbers from rest of the variables in input statement and then try again.

New Contributor
Posts: 4

Re: format numeric with positive sign

RamKumar,

my answer is another.

Your suggestion is incorrect.

Super User
Super User
Posts: 7,682

Re: format numeric with positive sign

I would suggest you first try to convert the text version into numeric.  It may be that those numbers are too long for SAS to handle.

SAS(R) 9.2 Language Reference: Concepts, Second Edition

There are other topics on here that deal with large or very small numbers, here for instance: https://communities.sas.com/message/178740#178740

New Contributor
Posts: 4

Re: format numeric with positive sign

Thanks RW9 for your reply. My problem, maybe, is the positive sign. Do you know if in SAS don't works the positive sign?

Super User
Posts: 9,856

Re: format numeric with positive sign

You don't post what output you are looking for yet .

Super User
Super User
Posts: 7,682

Re: format numeric with positive sign

As far as I am aware, positive numbers are represented without plus symbols within SAS.  I would suggest stripping that out from the text before converting to number.  If you want to display the plus then it should be a simple proc format statement.

Super User
Posts: 7,386

Re: format numeric with positive sign

Use the numx20. informat to read the numbers. If you want GBV_AMT and NBV_AMT to be numeric, you must not use a $.... format.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,386

Re: format numeric with positive sign

And, with output formatted:

proc format library=work;

picture testnum ()

  low -< 0 = '9999999999999,99'

    (prefix='-' decsep=',')

  0 = '09999999999999,99'

    (decsep=',')

  0 <- high = '9999999999999,99'

    (prefix='+' decsep=',')

;

run;

data test;

x = input("+0000000000027389,60",numx20.);

put x testnum18.;

x = input(" 0000000000000000,00",numx20.);

put x testnum18.;

x = input("-0000000000027389,60",numx20.);

put x testnum18.;

run;

Log:

+0000000027389,60

  0000000000000,00

-0000000027389,60

(The forum SW fails to display the output correctly, just try the code)

Be aware that the picture format in SAS does not allow for more than 16 digit characters ('0' or '9') in the definition, so the output is shorter than the input. If you need output exactly like the input, you will have to build the string manually.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 168

Re: format numeric with positive sign

When I ran your code in EG 5.1, I got the below error

proc format library=work;

18         picture testnum()

19           low -< 0 = '9999999999999,99'

ERROR: The quoted string '()   LOW -<' is not acceptable to a numeric format or informat.

20             (prefix='-' decsep=',')

21           0 = '09999999999999,99'

22             (decsep=',')

23           0 <- high = '9999999999999,99'

24             (prefix='+' decsep=',')

25         ;

NOTE: The previous statement has been deleted.

26         run;

Super User
Posts: 7,386

Re: format numeric with positive sign

I got

15     GOPTIONS ACCESSIBLE;
16     proc format library=work;
17     picture testnum ()
18       low -< 0 = '9999999999999,99'
19         (prefix='-' decsep=',')
20       0 = '09999999999999,99'
21         (decsep=',')
22       0 <- high = '9999999999999,99'
23         (prefix='+' decsep=',')
24     ;

NOTE: Format TESTNUM is already on the library.

NOTE: Format TESTNUM has been output.

25     run;

NOTE: PROCEDURE FORMAT used (Total process time):

  real time       0.00 seconds
  cpu time        0.00 seconds

SAS is 9.2 TSM3.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: format numeric with positive sign

Thank you Kurt!!

Ask a Question
Discussion stats
  • 11 replies
  • 755 views
  • 3 likes
  • 5 in conversation