- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data format;
input id weight date1 ddmmyy8.;
format id dollar8.2 weight comma10. date1 ddmmyy8.;
datalines;
189 1450 30-12-16
249 1679 30-12-16
3456 1958 30-12-16
5454 2205 30-12-16
;
proc print;
run;
informat id comma10.;
put id;
proc print;
run;
I wrote the above program after reading some info about the Informat but like it says in the text, informat statement is not removing the dollar sign ($) and period(.) and I'm getting same output in both the print procedures. Please let me know where I'm doing this wrong. Thank you:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would expect that your program has some errors in the log. Your INFORMAT statement is not used correctly or in the right place and your PUT statement is also incorrectly positioned. INFORMAT only strips out punctuation and special characters when you read data into SAS or when you convert a character variable INTO a numeric value.
I suggest you read more about using informats and write more programs to prove to yourself that informats, used correctly, will produce the desired results.
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
use format not informat
data format;
input id weight date1 ddmmyy8.;
format id dollar8.2 weight comma10. date1 ddmmyy8.;
datalines;
189 1450 30-12-16
249 1679 30-12-16
3456 1958 30-12-16
5454 2205 30-12-16
;
proc print data=format;
format id comma10.;
run;
proc contents data=format;
run;
Obs | id | weight | date1 |
---|---|---|---|
1 | 189 | 1,450 | 30/12/16 |
2 | 249 | 1,679 | 30/12/16 |
3 | 3,456 | 1,958 | 30/12/16 |
4 | 5,454 | 2,205 | 30/12/16 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Maxim 2: Read the Log.
informat and put are data step statements and cannot be used outside of a data step.
I do not see any dollar signs or periods in your datalines that need to be removed.
"ID" values are (usually) not used in calculations and should therefore be stored as character. Why do you store them as numbers and assign a dollar display format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Formats convert values to text. They are used when displaying the data. In code you can use them in PUT statement or PUT() function.
Informats convert text into values. They are only used when reading text. So they are used by INPUT statement or INPUT() function.