DATA Step, Macro, Functions and more

Is it possible to view the fileref contents?

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

Is it possible to view the fileref contents?

Hi, All,

I am trying to debug a program and want to take a close look into the fileref contents.

For example: In the following codes, certain info was written into 'lst_out' when 'proc print' was executed.

Is there any way I can know what is in the 'lst_out'?

Thanks.

data have;

var=123;

run;

filename lst_out temp;

proc printto new print = lst_out ; run;

proc print data=have;

run;

proc printto;

run;

/* check if fileref "lst_out" exist?  No = 0 */  

data a;  

exist=fexist ("lst_out");  

put;

put "Fileref curdirfl exist? " exist=;  

run;


Accepted Solutions
Solution
‎12-01-2014 04:22 PM
PROC Star
Posts: 7,492

Re: Is it possible to view the fileref contents?

Since it was defined as a temporary file, depending upon how your system is setup, the file might only be viewable during the session when the code was run.

It is a text file that is written to your work directory. On Windows, you can open it with any text editor, but it will have a randomly assigned name.

During the active session you can find out where the file was written by running:

%let pgmpath = %sysfunc(pathname(lst_out));

%put &pgmpath;

View solution in original post


All Replies
Solution
‎12-01-2014 04:22 PM
PROC Star
Posts: 7,492

Re: Is it possible to view the fileref contents?

Since it was defined as a temporary file, depending upon how your system is setup, the file might only be viewable during the session when the code was run.

It is a text file that is written to your work directory. On Windows, you can open it with any text editor, but it will have a randomly assigned name.

During the active session you can find out where the file was written by running:

%let pgmpath = %sysfunc(pathname(lst_out));

%put &pgmpath;

Contributor
Posts: 61

Re: Is it possible to view the fileref contents?

To Arthur,

I am running EG on server, and after run the codes

%let pgmpath = %sysfunc(pathname(lst_out));

%put &pgmpath;

, I got this path in the log

/SASWork/SAS_workA48102BC003A_ualbsasapp1/#LN00093

So, How to locate this file and maybe open it (what kind of format is it)?

Thanks.

PROC Star
Posts: 7,492

Re: Is it possible to view the fileref contents?

I'm not sufficiently familiar with EG to provide any advice. The path you received is the direct path to the file but, depending upon your site's EG settings, the file and directory might be deleted as soon as the run completes.

It is just a text file, although it might contain some printer-specific codes, like page change, etc.

If there is a way for you to print a txt file while you are in EG, the file shown in the path is the one you'd want to print.

Super Contributor
Posts: 387

Re: Is it possible to view the fileref contents?

If you're running EG on the remote server, then SAS is your "portal" to the server, unless you can remote login to the server (i.e. RDP for Windows or Putty for Unix).

However, if all you're wanting to do is see the contents of the file for debugging purposes, then this should work:

data have;

var=123;

run;

filename lst_out temp;

proc printto new print = lst_out ; run;

proc print data=have;

run;

proc printto;

run;

data _null_;

infile lst_out;

input;

putlog _infile_;

run;

I'm not in front of EG right now, but there may be a task to copy a remote file to your local system, analogous to FTP.

HTH,

Scott

Super User
Super User
Posts: 7,076

Re: Is it possible to view the fileref contents?

Use the PATHNAME() function to get the physical name to pass to the FILEEXIST() function.

filename test1 temp;

data _null_;

  exist=fileexist(pathname('test1')) ;

  put exist=;

run;

ods _all_ close;

ods listing file=test1 ;

proc print data=sashelp.class ; run;

ods listing close;

ods listing;

data _null_;

  exist=fileexist(pathname('test1')) ;

  put exist=;

run;

Contributor
Posts: 61

Re: Is it possible to view the fileref contents?

Hi, ALL,

Thanks for your inputs.

Your codes work if I run SAS on my computer.

However, I still have no idea where to find it if it is run on the server.

But by checking what is going on inside the local computer I know what to do next.

Thanks.

Joe

Super User
Super User
Posts: 7,076

Re: Is it possible to view the fileref contents?

Not sure I understand the question here.  What reason do you want to look at the file?  And if you want to look at it why are you making it as a temporary file?  

Perhaps what you want is to use the upload/download custom task that Chris has blogged about.

http://blogs.sas.com/content/sasdummy/2013/11/25/11-custom-tasks/

Contributor
Posts: 61

Re: Is it possible to view the fileref contents?

Yeah, You are right, Tom. I can make it a permanent file so that I can look at it easily. should have done that earlier. Thanks for reminding me. I will also read the blog you shared. Thank you.

Basically, I am debugging a macro written by somebody else. The problem is: There is a macro variable in the macro. The macro variable is created from the temp fileref. This particular macro variable will only resolve if you run the macro two or more batches together. For example:

if you do

% themac (data1);

it will not resolve for data1.

if you do

% themac (data1);

% themac (data2);

% themac (data3);

it will resolve correctly for data2 and data3, but not for data1.

The only way to get it resolved for data1 is to change the order of the runs, like,

% themac (data2);

% themac (data1);

% themac (data3);

In this case, again it will not resolve for data2.

I will keep working on this issue recently. I don't have a sample macro to show this problem yet. I may make one later and ask for extra help here.

Contributor
Posts: 61

Re: Is it possible to view the fileref contents?

Hi, ALL,

I was able to see the output information in the fileref. Now, the follow-up question was posted out at:

Nothing was delivered out for the 1st run for some reason.

Pls take a look at the post and give opinions if you can. Thanks.

Joe

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 493 views
  • 7 likes
  • 4 in conversation