10-01-2014 11:01 AM
1. How to read the space delimited strings as one variable in data step? Ideally I wish to create the table as below with one variable instead of many. Since I've spaces between the strings I couldn't succeed with the data step. Once I created a dataset then I can easily remove the middle characters (m r as per inputs below) via scan & compress function to proceed further for my analysis.
Input name$ ;
Ra m ku
Ch r is
2. My external file has a header like c:name c:zip c:address. Once I import this .csv via proc import, sas dataset variables turn out to be c_name c_zip c_address. i.e. ':' are converted into '_'. How to get rid of this behavior?
I ran all my SAS code in EG 5.1.
Many thanks in advance for your inputs.
10-01-2014 11:31 AM
Be happy it did that as the headernames are not valid sas-names. This is one of the aspects of using proc import, guessing.
Spaces in a string with a datastep can be handled in many ways, as usual it depends on more contraints. Singel/multiple blanks other recognitions.
10-01-2014 02:25 PM
For the formats you have:
- $varying. SAS(R) 9.4 Formats and Informats: Reference that is apllicable working through the record knowing the length at some moment,
For the input statement list
- SAS(R) 9.4 Formats and Informats: Reference there are modifiers. : & ~
& one space is embedded space going into the variable and than two spaces are the real separation
~ allows quoted strings with space to be processed
For the infile statement you have SAS(R) 9.4 Statements: Reference, Third Edition:
- length=variable is giving you the length of the read record.
- col=variable is giving the position of cursor the input statement is.
- The automatic _INFILE_ variable is filled with the complete record. Available to count the words
With combining some methods you can handle almost every data-structure as long it is logical defined is some known way.
In you example I would prefer the & modifier as it just 1 variable at each dataline .