BookmarkSubscribeRSS Feed
mdoddala
Obsidian | Level 7

informat.PNG

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:)

4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
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
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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
Kurt_Bremser
Super User

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?

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1321 views
  • 2 likes
  • 5 in conversation