Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work.

Similar presentations


Presentation on theme: "1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work."— Presentation transcript:

1 1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work

2 2 Introduction Aim: To develop an automated process to save the contents of the editor window to a back up file every time code is submitted Use: To keep an updated copy of all code submitted in case of loss from crashing the SAS session or overwriting files Concepts: PC SAS, windows platform, enhanced editor window Submitting code using a shortcut key: Single back up file overwritten with each submit Rolling back up files

3 3 Back Up File: Rewriting Over One File Save the contents of the editor window with each submit Submit code using a shortcut key Assign commands to the shortcut key in the keys window: clear log; clear out; file ‘c:\backup\lastprog.sas’ replace; submit; Advantages: Neat and easy to implement Keeps a back up of current work Disadvantages: Can overwrite the back up before retrieving lost code

4 4 Rolling Back Up Files Concepts: Submit code in enhanced editor window using a shortcut key Shortcut key runs a saved SAS program from the PGM window Entire contents of enhanced editor window are saved to a back up file Submitted code is run 10 back up files are created and sequentially overwritten, oldest first Program contains PIPE device type with filename statement, SAS code and DM commands

5 5 PIPE Device Type Execute operating system commands directly through the FILENAME statement For example, get file properties from a directory on your c: drive filename backup pipe 'dir C:\backup /t:w /a:-d /OD'; /t:w – time last written /a:-d – file information only, not directories /OD – order = oldest files first

6 6 PIPE Device Type Use the fileref ‘backup’ to reference information gathered. Volume in drive C has no label. Volume Serial Number is 4C53-A158 Directory of C:\backup 19/09/2006 20:24 2,362 bprog.sas 30/01/2007 23:25 55 backup2.sas 30/01/2007 23:25 55 backup3.sas 30/01/2007 23:25 55 backup4.sas 30/01/2007 23:25 55 backup5.sas 30/01/2007 23:25 55 backup6.sas 30/01/2007 23:25 55 backup7.sas 30/01/2007 23:25 55 backup8.sas 30/01/2007 23:25 55 backup9.sas 30/01/2007 23:25 55 backup10.sas 30/01/2007 23:25 55 backup1.sas 11 File(s) 2,912 bytes 0 Dir(s) 27,278,381,056 bytes free

7 7 DM Commands Control the windows (output, log, enhanced editor, program editor) and their contents Enter on the command line, use in conjunction with shortcut keys for commonly used commands clear out; clear log; resize; pgm Can also be run from editor window dm 'wpgm; file "c:\backup\backup1.sas" replace;’;

8 8 Rolling Back Up Files Advantages: Much less chance of overwriting lost code Limitations: Takes a little longer to run with first submit A small line of code appears in the log ** Submitting program **; dm 'cle log; sub;'; The PGM window will briefly open when you ‘submit’ You must specify the data set name when you run procedures if you are running your code piece by piece

9 9 Rolling Back Up Files - Example Keys: Type KEYS on the command line in SAS Chose an unused shortcut key Type the following commands: pgm; inc ‘c:\backup\bprog.sas’; submit; These commands result in moving from the enhanced editor window to the program editor window, including bprog.sas in the program editor window and submitting the program.

10 10 Rolling Back Up Files - Example Code: %let bck=1; Initialize macro variable filename backup pipe 'dir C:\backup /t:w /a:-d /OD'; Create data set from backup fileref, keep names and order data backup(keep=fname orda); infile backup missover pad length=len; input @01 line $varying200. len; if index(upcase(line),' BACKUP'); fname=input('B'||scan(compress(upcase(line)),2,'B'),$20.); orda+1; run;

11 11 Rolling Back Up Files - Example Code (continued): Create table backup1 containing names, order and the total number of backup files already in existence proc sql; create table backup1 as select (select max(input(reverse(scan(reverse(fname),2,'.P')),3.)) from backup) as maxnum, a.* from backup a; quit;

12 12 Rolling Back Up Files - Example Code (continued): Select first observation from backup1 data set (oldest file) If not all 10 files in existence create macro variable as oldest file number +1 If all 10 files in existence create macro variable as number of oldest file data _null_; set backup1 (obs=1); if maxnum lt 10 then call symput('bck',compress(put(maxnum+1,2.))); else call symput('bck',compress(reverse(scan(reverse(fname),2,'.P')))); run;

13 13 Rolling Back Up Files - Example Code (continued): Tidy up and delete work data sets no longer required proc datasets lib=work; delete backup backup1; quit; run; Run DM commands (see next 2 slides for details) dm 'wpgm; file "c:\backup\backup&bck..sas" replace; %symdel bck; resi; cle out; pgm off' editor; ** Submitting program **; dm 'cle log; sub;';

14 14 DM commands WPGM - moves to the enhanced editor window FILE - saves the contents of the current window to the specified file RESI - abbreviated command for RESIZE, will return the enhanced editor window to your standard sizing CLE OUT - abbreviated command for CLEAR OUT, clears the output window PGM OFF - shuts the program editor window as this is no longer required EDITOR - ensures the program editor window closes as it is opened when commands are run from the enhanced editor window dm 'wpgm; file "c:\backup\backup&bck..sas" replace; %symdel bck; resi; cle out; pgm off' editor;

15 15 DM commands CLE LOG - abbreviated command for CLEAR LOG, clears the log window SUB - abbreviated command for SUBMIT, submits the contents of the enhanced editor window ** Submitting program **; dm 'cle log; sub;';

16 16 Summary Rolling back up files are useful! PIPE device-type is handy for file management activities There are endless ways to control your SAS environment using DM commands Code can be customized to suit your SAS editor window preferences Suggested enhancements: Add code to zip and email files periodically Add code to copy to a server http://www2.sas.com/proceedings/forum2007/037-2007.pdf


Download ppt "1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work."

Similar presentations


Ads by Google