1 / 16

Back Up with Each Submit

Back Up with Each Submit. One approach for keeping a dynamic back up copy of your current work. 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:

Download Presentation

Back Up with Each Submit

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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. 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. 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. 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. 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/200620:242,362 bprog.sas • 30/01/200723:2555 backup2.sas • 30/01/200723:2555 backup3.sas • 30/01/200723:2555 backup4.sas • 30/01/200723:2555 backup5.sas • 30/01/200723:2555 backup6.sas • 30/01/200723:2555 backup7.sas • 30/01/200723:2555 backup8.sas • 30/01/200723:2555 backup9.sas • 30/01/200723:2555 backup10.sas • 30/01/200723:2555 backup1.sas • 11 File(s) 2,912 bytes • 0 Dir(s) 27,278,381,056 bytes free

  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. 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. 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. 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. 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. 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. 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. DM commands dm 'wpgm; file "c:\backup\backup&bck..sas" replace; %symdel bck; resi; cle out; pgm off' editor; 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

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

  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

More Related