- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to manually generate data with the datalines statement. I can't seem to figure out how to properly get correct values for percents and dollar values. This is what I have right now. Have tried different formats but can't get it to work.
data test;
infile datalines;
format Current_Cost dollar3.2 Target percent8.2;
input Current_Cost dollar3.2 Target percent8.2;
datalines;
$40.00 76.41%
$30.00 76.21%
$20.00 50.36%
$10.00 20.22%
$23.00 24.91%
$45.00 86.12%
;;
run;
I want them to display exactly as they are in the datalines. But right now it is coming out as this:
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First, get rid of the unneeded characters in your inputs, so that the inputs are entirely numeric (and a decimal point).
Then, you don't need the informats in the INPUT statement.
If you want the dollars to come out as $40.00 then you want format DOLLAR5.2 (or bigger, such as DOLLAR10.2, if you will have many more digits to the LEFT of the decimal point.)
I leave it up to you to play with the format for percent until you get it to work the way you want it.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First, get rid of the unneeded characters in your inputs, so that the inputs are entirely numeric (and a decimal point).
Then, you don't need the informats in the INPUT statement.
If you want the dollars to come out as $40.00 then you want format DOLLAR5.2 (or bigger, such as DOLLAR10.2, if you will have many more digits to the LEFT of the decimal point.)
I leave it up to you to play with the format for percent until you get it to work the way you want it.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For your exampe:
data test; infile datalines truncover; format Current_Cost dollar6.2 Target percent8.2; input Current_Cost dollar6.2 Target percent8.2 ; datalines; $40.00 76.41% $30.00 76.21% $20.00 50.36% $10.00 20.22% $23.00 24.91% $45.00 86.12% ;; run;
Problems: when you say 3.2 you mean read a value with a length of 3 characters and 2 of them are decimals. So a Dollar3.2 format has lots of problems as the $ takes one position, the . takes a second and that doesn't leave much. You need to count every likely displayed character in the w part of a format that has the w.d option to set the W part. Your informat of percent failed because you requested 8 characters but the value only had 6. So the line of data ran out. The TRUNCOVER option says to read what is present and truncate the data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Okay this is the final solution - I changed the values of the percents. Thank you both for your help.
data test;
infile datalines;
format Current_Cost dollar6.2 Target percent8.2;
input Current_Cost Target;
datalines;
40 .7641
30 .7621
20 .5036
10 .2022
23 .2491
45 .8612
;;
run;