BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Dear all,
I tried to output the below data but kept getting errors. Could somebody help me? Thanks a lot.
I attach my code as well.

12244 $1,499.99 144
32189 $20,000 1
92314 49.28 3

data temp;
input Invoice 5. Amount dollar26.2 Quantity ;
format Invoice 5. Amount dollar26.2 Quantity;
cards;

12244 $1,499.99 144
32189 $20,000 1
92314 49.28 3
;
proc print;
run;
3 REPLIES 3
OS2Rules
Obsidian | Level 7
Penny:

Try this - there are minor changes:

data temp1;
input Invoice 5. Amount Quantity ;
format Invoice 5. Amount dollar26.2 Quantity 5.;
cards;
12244 1499.99 144
32189 200.00 1
92314 49.28 3
;
proc print;
run;
Cynthia_sas
Diamond | Level 26
An alternative to changing your data is to use the colon modifier to read the data using a specific informat.

You show your data with dollar signs, which are invalid in a number (valid for formats, but invalid for reading with the standard numeric format.)

So, instead of this:
input Invoice 5. Amount dollar26.2 Quantity ;

you would have
input Invoice 5. Amount : comma26. Quantity ;


The nice thing about the comma informat is that it detects dollar signs, commas and decimal points and essentially strips the dollar signs and commas from the number before storage. (It also deals with parentheses, percent signs and dashes, etc.)

If you have any more problems reading your data, your best bet might be to contact Tech Support, as there are other issues you might run into or need to put into your program (such as an INFILE statement that points to a data file instead of a CARDS statement with in-line data or an INFORMAT statement).

Also, even if you want your formatted length to be 26.2, you do NOT have to read the data with that same informat. Sometimes, specifying a decimal place holder when you read a number could cause the insertion of a decimal point where you don't want it. You have to be certain that ALL the numbers in your file have a decimal point in order to use an informat with a decimal indicator.

To find out how to contact Tech Support, refer to this site: http://support.sas.com/techsup/contact/index.html

Good luck!
cynthia
deleted_user
Not applicable
Thanks a lot for your help!!!!!!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1283 views
  • 0 likes
  • 3 in conversation