DATA Step, Macro, Functions and more

How to recover last code

Reply
Occasional Contributor
Posts: 17

How to recover last code

Hi,

 

I have one doubt that suppose I am working in work library.

 

data a;

set sasuser.admit;

run;

 

session is not ended yet. So, wanted to know that is there any process which let me know for dataset a which code was run ??

Trusted Advisor
Posts: 1,363

Re: How to recover last code

The answer depends on your SAS environment:

 

In SAS Studio you can just go to CODE window;

In regular SAS status is displayed on top of program ediror window;

in any SAS O/L environment you can look at the LOG window.

In unix environment you can run on xterm the ps -ef | grep sasexe command.

 

I don't think you can answer a question as: which process created work.a table, except

if you can recall last code submitted until 1st time you find a step creating data a;

 

Occasional Contributor
Posts: 17

Re: How to recover last code

Hi, Thanks for your reply. I am thinking if other than log can provide us the information.
Trusted Advisor
Posts: 1,363

Re: How to recover last code

One more possibility: you can save the program name in the dataset label,

by: data a(label="created by program...");

Super User
Posts: 10,466

Re: How to recover last code

If you have saved the program file bebore running then code similar to this:

data work.junk (label=%sysget(SAS_EXECFILENAME));
   set sashelp.class;
run;

 

will put the name of the running program file in the data set label. Which can be viewed in the SAS Explorer data set properties or seen in the description column of explorer.

 

But nothing much retroactively.

Occasional Contributor
Posts: 17

Re: How to recover last code

Hi, Thanks for your reply.

 

As this approach can help you in the  current session.

I just want to know suppose I have created  permanent dataset in a library say a.

then after I close the sas session. I want to get a previous log or any other info which tell me which code was submitted to create a dataset a ? 

 

Thanks in Advance.

Super User
Posts: 10,466

Re: How to recover last code

The code I showed above sets the data set label (or description) if you prefer. It will stay with that value until you change it.

There is nothing in SAS I am familiar with that will retroactively do what you you want  unless, possibly, you implement a source code management system and reference that for which programs create data sets.

 

Or use an operating system search tool to look in program files that may reference the data set.

Trusted Advisor
Posts: 1,363

Re: How to recover last code

I can think of few ways to save traces of work:

 

1) you can save the log files, of each run, under name containing a timestamp (date and time) in a dedicated directory

 

2) you can save a dataset and append a record for each run with any desired information

 

3) as said before, you can enter upto 240 characters into the dataset label as text, in any format you decide.

 

You may think of other solutions depending on your environment.

Ask a Question
Discussion stats
  • 7 replies
  • 479 views
  • 0 likes
  • 3 in conversation