Showing posts with label input. Show all posts
Showing posts with label input. Show all posts

Monday, September 7, 2009

PUT function vs. INPUT function

What about the relationship between them?

In my opinion, INPUT function is the inverse process of PUT function.
PUT function: convert the variable value to a character string
INPUT function: convert a character string to the variable value

Tuesday, February 3, 2009

defensive programming when using multiple INPUTs

When there are more than one INPUT statements in DATA step, we should care about end-of-file issue. Before INPUT, we should check the enf-of-file to avoid DATA step execution stop.

It should be something like below:

infile in end=end; *or eof= option;
input;
* something here;
if not end then do;
input;
* something here ;
end;
* something here;

if end then do;
* something here;
end;

Tuesday, December 2, 2008

Useful informat modifiers

The world is not perfect. Likewise, raw data is not always clean.
With SAS powerful input facility, we can handle different format data.

There are four input styles: column, list, formatted and named.
In my opinion, the most powerful and interesting style is formatted.

Here are 4 useful modifiers, which can be used in formatted input.
#1: colon format modifier (:)
character data that contains more than eight characters
numeric data that contains special characters.
#2: ampersand format modifier (&)
character data that contains single embedded blanks.
Note: The only restriction is that at least two blanks must divide each value from the next data value in the record.
#3: double question mark modifier (??)
Suppress the error messages resulting from invalid data/argument. This can be used in INPUT function and INPUT statement. The modifier also resets the automatic variable _ERROR_ to 0.
#4: single question mark modifier (?)
Suppress the error messages resulting from invalid data/argument. This can be used in INPUT function and INPUT statement.

Compared with informat modifier, there are format modifier for PUT function at below.
-L left aligns the value.
-C centers the value.
-R right aligns the value.

Obviously, format modifier is not much useful.