There are often times when it is useful to read the same raw data columns more than once to create different SAS data set variables.You can read the exact same range of columns multiple times and create variables of different types (e.g.numeric, character, date, etc.),or read a subset of a previously read column range into a new variable,or even read overlapping ranges into different variables.
Suppose you are dealing with inventory data where it is important to know in which state a part was manufactured,the weight of the part,and the year in which it was made.Each part has a 14-character part ID made up of four components: a two-character state code,a three-digit part number,a three-digit part weight,and a six-digit manufacture date in MMDDYY format.Each part also has a description and a quantity-on-hand value.
You have to build a SAS data set that includes the following independent variables:PARTID (part ID),ST (state of manufacture),WT(part weight),YR(year of manufacture),PARTDESC (part description),and QUANT (quantity on hand.)PARTID must be read as a character variable because it contains alphanumeric characters (the state abbreviations).You also want ST read separately.
WT must be read as a numeric variable because you have to do arithmeticcalculations with it(e.g.total weight for all pieces in the warehouse).You only need the year at present for YR,so you don't read the entire date.Once again,there are many ways to accomplish your task.The following coderepresents one method:
PARTID is first read as a 14-byte character variable starting in column 1. By re-reading columns 1 and 2, you obtain a value for the 2-byte character variable, ST.You then read data from within the same column range that you read as character for PARTID and obtain two numeric variables: WT fromcolumns 6-8 and YR from columns 13-14.
The INPUT statement completes the process by reading in a 24-byte character variable PARTDESC starting in column 16 and a 4-byte numeric variable QUANT starting in column 41.The previous code yields the following output:
Output from Example- Reading Parts of Your Data More Than Once
There are actually other ways to accomplish these goals (but there aren't better ways to get basic concepts across.) You could use character substring functions and date functions and PUT and INPUT functions, etc.,but let's wait until Chapter 5, "SAS Functions," to meet these powerful tools.
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.