DATA Step, Macro, Functions and more

4 methods to read a file in SAS program --Please provide the information !!thanks

Reply
New Contributor
Posts: 2

4 methods to read a file in SAS program --Please provide the information !!thanks

Hi , I am using(mainframe) for last 8 months only . In one interview I was asked  that there are 4 methods to read a file in SAS program . Could you please provide me the four methods .

SAS Super FREQ
Posts: 8,743

4 methods to read a file in SAS program --Please provide the information !!thanks

Hi,

  Without knowing more specifically about what type of file (because, the method you would use to read an Oracle file, for example, differs from the method you would use to read a raw data file). However, if you look at the documentation, I believe you will find the answer to that question:

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a002645704.htm

There are mainly three ways to read raw data files into a SAS program to create a SAS dataset: LIST input, COLUMN input and FORMATTED input and then, since you can "mix" types of input, some people consider MIXED input (where you use LIST and COLUMN or COLUMN and FORMATTED or ...)  to be a 4th method.

cynthia

Super User
Posts: 9,681

4 methods to read a file in SAS program --Please provide the information !!thanks

Add it into Cynthia ,The fourth method is NAMED input.

Ksharp

SAS Super FREQ
Posts: 8,743

4 methods to read a file in SAS program --Please provide the information !!thanks

True....I haven't used it in so long, I forget it's even there. So did the doc site I listed. So I guess that's 5 overall -- if you count NAMED -and- the ability to mix the input types.

cynthia

Contributor
Posts: 35

4 methods to read a file in SAS program --Please provide the information !!thanks

That question can be interpreted more than one way. The others have mentioned the various forms of an INPUT statement, which may very well be what was intended. However, looking at the question from a different point of view, four methods to read a file that I can think of would be INFILE, PROC IMPORT, LIBNAME (using a non-default engine) and %INCLUDE.

Regular Contributor
Posts: 184

4 methods to read a file in SAS program --Please provide the information !!thanks

Yes, it does depend on interpretation. I can think of only (1) the INPUT statement and (2) the FREAD function. Others (PROC IMPORT, External File Interface, Enterprise Guide) arguably don't count because they simply generate code for #1.

Valued Guide
Posts: 2,175

4 methods to read a file in SAS program --Please provide the information !!thanks

Are we to allow a "file" to include a database such as a sql server "file"?

Then a SAS program might "read" that "file" with the ODBC libname engine.

A file might be a sas table.

A SAS program reads such a file with many different methods, that vary not just within the capabilities of a DATA step but also over the many different PROC steps and sometimes varying with the platform on which SAS is running.

DATA step INPUT statements offer a large variety of methods (more than 4). FREAD provides a different approach to reading a file in a DATA step (or even in the macro language environment).

Perhaps PROC SOAP should be considered too, as its online doc starts "PROC SOAP reads XML input from a file" .....

that interview question is beginning to sound a bit vague...  which is OK for an interview as it opens up a conversation, at least to clarify and expand on that question .....

The interviewer might want to hear more that a quick list of 4

peterC    

Ask a Question
Discussion stats
  • 6 replies
  • 195 views
  • 0 likes
  • 6 in conversation