DATA Step, Macro, Functions and more

questions - input statement & proc import

Reply
Regular Contributor
Posts: 168

questions - input statement & proc import

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.

data A;

Input name$ ;

Datalines;

Ra m ku

Ch r is

;

run;

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.

Valued Guide
Posts: 3,208

Re: questions - input statement & proc import

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. 

---->-- ja karman --<-----
Regular Contributor
Posts: 168

Re: questions - input statement & proc import

May I request you to supply the code to handle the spaces in strings for my requirement?

Valued Guide
Posts: 3,208

Re: questions - input statement & proc import

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 .   

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 3 replies
  • 225 views
  • 3 likes
  • 2 in conversation