BookmarkSubscribeRSS Feed
Andygray
Quartz | Level 8

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?

7 REPLIES 7
LinusH
Tourmaline | Level 20

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
Tom
Super User Tom
Super User

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.

Andygray
Quartz | Level 8

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? 

art297
Opal | Level 21

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;

Tom
Super User Tom
Super User

"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.

art297
Opal | Level 21

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;

Ksharp
Super User

Arthur.T ,

Good to INFILE is conditional executable .

Xia Keshan

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 712 views
  • 1 like
  • 5 in conversation