why is Infile an "EXECTUABLE" statament?

Reply
Contributor
Posts: 59

why is Infile an "EXECTUABLE" statament?

I read the documentation to understand the infile statement functionality. The definition is clear that it specifies the external file to read with an input statement. And it makes sense input being an executable statement as it assigns values to corresponding variables. What functionality of infile makes it executable as opposed to being called DECLARATIVE?

if exectuable can it be used in an if then like-

if x=1 then infile "fileref";

Can anybody help?

Super User
Posts: 5,384

Re: why is Infile an "EXECTUABLE" statament?

Why are you asking? Do you have an issue with this...?

The why should maybe asked the Base SAS developers, by I presume that you may need the option to have separate infiles or infile options depending on another condition.

But I can't say that I have used this opportunity in my SAS life...

Data never sleeps
Super User
Super User
Posts: 6,844

Re: why is Infile an "EXECTUABLE" statament?

Because it does stuff every time that data step loops past it.

Consider the FILEVAR option for example.  With this you can dynamically set the file that the INFILE statement is referencing.

Contributor
Posts: 59

Re: why is Infile an "EXECTUABLE" statament?

Hi Tom/Art,

I agree that it does stuff. Well, it is also proving how much of a newbie i am with my lack of understanding. Forgive me. But saying that, it does stuff?, We could say any declarative statement does stuff too. For example, when we assign initial values to a variable in a retain statement , that is written to the output dataset, and likewise for array, when we initialize variable values, that's also written to dataset too. But by definition they are still declarative or compile time statements right?

Art's example is cool. I understand based on a condition input reads values from different external file. Nevertheless, is Infile an independent executable statement? 

PROC Star
Posts: 7,433

Re: why is Infile an "EXECTUABLE" statament?

Andy,

Declarative statements aren't re-compiled with each iteration. e.g., using the same test data as before, what would you expect the following to do?:

data want;

  set driver;

  if x in (1,2) then do;

    retain z 1;

  end;

  else do;

    retain z 3;

  end;

  if x = 1 then infile "c:\temp\file1.txt";

  else infile "c:\temp\file2.txt";

  input y $;

run;

Super User
Super User
Posts: 6,844

Re: why is Infile an "EXECTUABLE" statament?

"Independent executable statement" doesn't really make sense in this context.  It is part of a DATA step.  What SAS calls a GLOBAL statement (FILENAME, LIBNAME, OPTIONS, etc) are more like an independent statement.

Statements like KEEP, RETAIN, FORMAT, LABEL are not executable because their effect is totally determined when the DATA step is compiled and before it starts running.

PROC Star
Posts: 7,433

Re: why is Infile an "EXECTUABLE" statament?

The answer to one of your questions is "yes". Run the following and take a look at the results:

data _null_;

  file "c:\temp\file1.txt";

  put "1";

  put "2";

  put "3";

  put "4";

  put "5";

  put "6";

  put "7";

run;

data _null_;

  file "c:\temp\file2.txt";

  put "a";

  put "b";

  put "c";

  put "d";

  put "e";

  put "f";

  put "g";

run;

data driver;

  input x;

  cards;

1

2

1

2

1

1

2

;

data want;

  set driver;

  if x = 1 then infile "c:\temp\file1.txt";

  else infile "c:\temp\file2.txt";

  input y $;

run;

Super User
Posts: 9,867

Re: why is Infile an "EXECTUABLE" statament?

Arthur.T ,

Good to INFILE is conditional executable .

Xia Keshan

Ask a Question
Discussion stats
  • 7 replies
  • 307 views
  • 1 like
  • 5 in conversation