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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 840 views
  • 1 like
  • 4 in conversation