- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
May you help with following converting the characer value with decimal into numeric value:
test = input( price, best12.) , it did not work.
Price: Format $7, informat $7.
example of price : 6.32, 0.11, 0.44, 11.73
Thank you.
Ivy
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Works for me. I'd have to think that you entered something wrong (e.g., missing semi-colon or the like).
The following works:
data have; format price $7.; informat price $7.; input price; cards; 6.32 0.11 0.44 11.73 ; data want; set have; test = input( price, best12.); run;
Art, CEO, AnalystFinder.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Works for me. I'd have to think that you entered something wrong (e.g., missing semi-colon or the like).
The following works:
data have; format price $7.; informat price $7.; input price; cards; 6.32 0.11 0.44 11.73 ; data want; set have; test = input( price, best12.); run;
Art, CEO, AnalystFinder.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your example statement should work. Make sure that your text string does not have non-printing characters like tabs, carriage returns or non-breaking spaces ('09'x,'0A'x,'A0'x, respectively).
data want ;
length price $7 ;
input price ;
test = input(price, 7.);
cards;
6.32
0.11
0.44
11.73
;;;;
A couple of notes.
- The LENGTH of a character variable is more important than what FORMAT or INFORMAT is attached to it. In fact the FORMAT can actually cause trouble if it doesn't match the length since it can make it hard to debug.
- BEST is really a FORMAT and not an INFORMAT. SAS will just use the 12. INFORMAT if you ask it to use BEST12. as in informat. Actually for reading text into numbers the COMMA informat is good one to use because it will ignore dollar signs and commas in your strings.
To see if your strings have non-printing characters print the value using $HEX format. '20'X is the code for a space.
Or you the COMPRESS() function to remove non digits. Something like this might help.
test = input(COMPRESS(price, "+.-", "d"),32.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Doesn't work is awful vague.
Are there errors in the log: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Also is your value for Price= '6.32' or '$6.32'? or does your Price have values separated by commas? Leading spaces? It isn't quite clear from your example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content