BookmarkSubscribeRSS Feed
King
Calcite | Level 5

data step to read these data into three variables: Invoice, Amount, and Quantity.

12244 $1,499.99 144

32189 $20,000 1

92314 49.28 3

I have written the below code

data testrun;

input invoice amount quantity;

informat amount dollar9.2;

cards;

12244 $1,499.99 144

32189 $20,000 1

92314 49.28 3

;

run;

There is no errors in log but it is reading all observations.but it is not correct, What is the problem. Thanks for the help

5 REPLIES 5
data_null__
Jade | Level 19

dollar9.0

zqkal
Obsidian | Level 7

Adding “$” in front of 49.28 for amount fix the problem. I think I you specify the dollar format all of you fields needs to have dollar($) sign.

data testrun;

input invoice

      amount dollar9.2

      quantity ;

format amount dollar9.2;

cards;

12244 $1,499.99 144

32189 $20,000   1

92314 $49.28    3

;

run;

proc print data=testrun;

run;

data_null__
Jade | Level 19

A missing $ sign is NOT the problem.  Do you think $20,000 is twenty thousand or $200.00?

King
Calcite | Level 5

It's $20,000 twenty thousand

Tom
Super User Tom
Super User

What DATA_NULL_ is trying to point out is that for an INFORMAT the decimal part of the informat is the number of decimal places to apply when the value read does NOT contain a decimal point.  When you specify dollar9.2 you are telling SAS to divide the 20,000 value by 100 in order to implement the implied decimal place.

Use dollar9.0 for the informat.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1117 views
  • 1 like
  • 4 in conversation