2
votes

I am using Sublime text editor to do the majority of my code writing in SAS. The only real issue is that I have to run the file in batch mode and cannot run individual bits of code easily. For the most part this does not bother me but occasionally it is nice to have SAS and Sublime open at the same time working on the same file. If I change something in SAS and save it sublime automatically refreshes the file and changes. Unfortunately, SAS does not return the favor. I have been messing around with using the autoexec.sas file and the display manager but I am having issues. This bit of code will close the file and open it again.

dm editor 'winclose' editor; dm editor 'inc "%sysget(SAS_EXECFILEPATH)"' editor;

I then tried to put this in a macro

%macro Refresh;
dm editor 'winclose' editor; 
dm 'inc "%sysget(SAS_EXECFILEPATH)"';
%mend;

and add the key definition

dm "keydef F12 '%NRSTR(%Refresh);";

When I hit F12 I get

ERROR: Two or more Commands Start with 'dm'. Please reenter.

Anyone have any ideas on how to fix this?

2
For some reason, my session does not allow me to rebind keys, so i cannot fully test, but 2 things: (1) just executing your %refresh macro by writing it in the code, works over here. (2) can't you bind it directly to the key by pressing F9 and then entering %refresh there yourself for the F12 key? (not posting as answer since i cannot verify )mvherweg
A possible work around? With .sas-file open both in SAS and sublime (or Vim): edit file in sublime, save in sublime, close file in SAS without saving, open recent file in SAS. This loads newest files with the edits made in sublime. With shortcut set up, this might be feasible.Rasmus Larsen

2 Answers

1
votes

I can't get that to work properly on my machine (the inc "...SAS_EXECFILEPATH..." does not work) but you definitely can remove the DM statements. Keys is intelligent, it will figure what context you are in; so for example, in KEYS, in F12 I type:

F12: winclose editor;

and it closes the editor window. Presumably you can use

F12: winclose editor; inc "something that works";

and that will work fine without all the DMs; or

F12: %refresh;

should also work.

0
votes

Maybe this could be a bit cleaner, but it works. There are two parts:

1 - Compile the code below

2 - Run the following line: %refresh();, in the program that needs to be refreshed (to pick up SAS_EXEC_FILEPATH). The line can then be deleted.

%macro Refresh(param=0);
%global file;
%if &param. =0 %then %do;
   %let file=%sysget(SAS_EXECFILEPATH);
   %put file (&file) saved successfully.;
%end;
%else %do;
   %put file being loaded =&file;
   wpgm;clear;wpgm; inc "&file";
%end;
%mend;

dm "keydef F12 '%NRSTR(%Refresh(param=1));'";

/* 
1 - compile this macro
2 - run this code IN THE PROGRAM THAT NEEDS TO BE REFRESHED 
    %refresh()
3 - press F12 to refresh, whether program is open or closed..
*/