BookmarkSubscribeRSS Feed
SASInd
Obsidian | Level 7

I have one field named 'Amount' which is in character format of 20 bytes i.e. $20. 

 

I want to perform Sort Sum on this amount field but I am getting error as character data can't be added up. Please suggest what needs to be done here? 

 

I have below amounts in my input file which has been set as $20. Also, I have tried changing $20. to PD format but no luck. I want to convert this in numeric format so that it will be printed as it is and sort sum can be performed.

 

-80.45

-202.07

33

126995.77

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data have;
input Amount $20.;
datalines;
-80.45
-202.07
33
126995.77
;

data want;
   set have;
   NumAmount=input(Amount, 20.);
run;
SASInd
Obsidian | Level 7

Hi @PeterClemmensen

 

I already tried the below code. But the amounts are not populating as expected.

The decimal digit places are not being printed. Also, I tried 20.2 but it it converting all the values with 2 decimal places.

 

When I ran code with 20.2 I got below result which is wrong.

 

  Input              Output

-79.34            -79.34
      0                0.00
      854            8.54
-202.07         -202.07

When I ran the code with 20. I got below results.

 

 Input              Output

-79.34               -79
      0                   0
      854            854
-202.07         -202.

 

          

Satish_Parida
Lapis Lazuli | Level 10

Why do you want to use 20.2?
You can use 20. or best12. as well based on the highest length.

Astounding
PROC Star

@PeterClemmensen provided the correct solution.  You are getting those results because you added to it something like:

 

format NumAmount 20.;

 

Get rid of the FORMAT statement.

SASInd
Obsidian | Level 7

Below is my code. it's not working properly for decimal places.

 

DATA WANT;
OPTIONS MISSING='#' LS=MAX PS=MAX ;
INFILE INPFL ;

INPUT @30 AMT $20.;

AMTN = INPUT(AMT, 20.);

FILE FLATFL;

PUT @30 AMTN 20.;

Astounding
PROC Star

So you applied the format in a PUT statement instead of a FORMAT statement.  Still, you got what you requested.  Change the PUT statement:

 

put @30 amtn 20.2;

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2763 views
  • 1 like
  • 4 in conversation