In addition to being able to read raw data values that are separated from each other by one or more spaces,the SAS System provides two methods of reading data values that are uniformly alignedin columns:column input and formatted input.Both provide the ability to read data from fixed locations in the input record,and both therefore expect to find the data in those locations.
Formatted input provides the additional feature of allowing you to read data that occur in other than standard numeric or character formats, but this is one of those "beyond the scope of this topics.
Column input and formatted input,as well as list input,can be freely intermixed within the same INPUT statement,as you will see in later examples in this chapter.A column INPUT statement can be used to read lines of data that are aligned in uniform columns.With this method,the name of the variable being read is followed by the column,or column range (starting and ending columns),containing the data for that variable. If you are defining a character variable,the identifying "$" comes before the column numbers.Here is an example.
This code produces the following output,Example (identical to that displayed in Example 1 except for the title.)
Output from Example - Reading Data Arranged in Columns
In this example,you do not leave any spaces between data values.You can if you wish,but unlike list input,it is not necessary to delimit the data values in any way.The column specifications in the INPUT statement provide instru ctions as to where to find the data values.Also, notice that we placed the value 99 (for the variable WEIGHT for observation 3) in columns 5-6 rather than in columns 4-5 as we did in previous examples.
Numbers placed right-most in a field are called right adjusted;this is the standard convention for numbers in most computer systems.You could have placed the 99 in columns 4-5 here as well because your instructions were to read the value for AGE anywhere in columns 4-6.The SAS System correctly reads the value even if it is not right adjusted, but it is a good habit to right adjust numbers in general since other computer programs aren't quite as smart as SAS software.
Making Your Program More Readable
Speaking of good habits,let's adopt another one.(If these habits truly yield more productive programming,then they will be easy to make and hard to break.)When using column and formatted input,it's worth the extra effort to code the variables in the INPUT statement in a uniform columnar fashion.It makes for easier code proofreading andmaintainability.Here is another version of the previous program that will yield exactly the same output (except for the title):
Notice that each variable name in the INPUT statement is on a separate line and that the column specifications all line up.This makes for a neater, easier to read, program.
Reading Selected Variables from Your Data
When you read data in columns,you indicate missing values by leaving the columns blank.You also have the freedom to skip any columns you wish and read only those variables of interest to you.If, for example,you only wanted to read ID and AGE from the previous data,you could use the following code:
This code produces the following output:
Output from Example - Reading Selected Variables from Your Date
Reading Values in Different Order
In this example you did not eliminate any data from the lines of data,but you chose to read only part of each line,specifically columns 1(ID) and 8-9 (AGE).When using column or formatted input,you can read data fields in any order you want to.You do not have to read them in order, from left to right, in ascending column order.You can also read column ranges more than once,or read parts of previously read ranges,or even read overlapping column ranges as different variables.The next set of code shows an example of reading the same data that you have been working with, but by jumping around the input record.
This code produces the following output:
Output from Example - Reading Values in Different Order
Notice that the variables exist in the data set COLINPUT,and are therefore displayed in the output,in the same order in which they are read via the INPUT statement.
SAS Programming Related Tutorials
|SASS (Syntactically Awesome Style sheets) Tutorial||R Programming language Tutorial|
SAS Programming Related Interview Questions
|Logistics Interview Questions||SAS Programming,SQL server Interview Questions|
|Clinical SAS Interview Questions||SASS (Syntactically Awesome Style sheets) Interview Questions|
|SQL Server Analysis Services (SSAS) Interview Questions||R Programming language Interview Questions|
|SAS DI Interview Questions||Advanced SAS Interview Questions|
|Base Sas Interview Questions||SAS Macro Interview Questions|
|Clinical Data Management Interview Questions|
Sas Programming Tutorial
Input And Infile
Set, Merge, And Update
Table Lookup Tools
Proc Means And Proc Uimivariate
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.