DATA Step, Macro, Functions and more

informat& format help

Reply
Occasional Contributor
Posts: 7

informat& format help

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

Respected Advisor
Posts: 3,799

Re: informat& format help

dollar9.0

Contributor
Posts: 47

Re: informat& format help

Posted in reply to data_null__

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;

Respected Advisor
Posts: 3,799

Re: informat& format help

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

Occasional Contributor
Posts: 7

Re: informat& format help

Posted in reply to data_null__

It's $20,000 twenty thousand

Super User
Super User
Posts: 7,074

Re: informat& format help

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.

Ask a Question
Discussion stats
  • 5 replies
  • 261 views
  • 1 like
  • 4 in conversation