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
SAS Super FREQ
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 679 views
  • 0 likes
  • 3 in conversation