BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhtlib
Calcite | Level 5

How to customize tools and add a button for commenting out selected text in enhanced editor?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

@hhtlib wrote:

Thanks. It's a good alternate for ctrl+/ keyboard shortcut. I am lazy and most of time just use one hand to move/click the mouse. So a button for commenting the select text would be the best. Wish we can assign same commands to a customized button like what we can do for keyboard shortcut.

 


I see three options:

 

  1. Use a mouse with programmable additional buttons. Then you could emulate an arbitrary sequence of keystrokes by pressing a custom mouse button. That sequence of keystrokes could be either an Enhanced Editor keyboard shortcut or simply the sequence of keystrokes by which you would comment out marked text manually. I think this is the most convenient option because you don't even need to move your mouse and hit a small target area on the screen, but just click a mouse button.

  2. Create an .exe file (say cmt_out.exe) that emulates the sequence of keystrokes needed for commenting out (see above), e.g. with AutoIt, and make it available to the OS. Then create a button in the Enhanced Editor (Tools --> Customize... --> Customize --> Add tool) and associate it with the command gsubmit "%sysexec cmt_out;".

  3. If neither new hardware nor custom .exe files are allowed in your work environment, you can create a button in the Enhanced Editor (see item 2 above) and associate it with the command, say, gsubmit "%inc 'C:\Temp\cmt_out.sas';" where cmt_out.sas is a program along the lines of this:
    options nonotes nosource;
    filename _cb clipbrd;
    filename _tmp temp;
    
    dm 'wcopy';
    
    data _null_;
    infile _cb;
    file _tmp;
    input;
    put _infile_;
    run;
    
    data _null_;
    infile _tmp;
    file _cb;
    input;
    _infile_='/* '||_infile_||' */';
    put _infile_;
    run;
    
    filename _cb clear;
    filename _tmp clear;
    options notes source;
    
    dm 'wpaste';
    This program copies marked text into the Windows clipboard, reads the text from the clipboard, writes it to a temporary file, reads it from there, encloses each line in C-style comments, writes this commented text back to the clipboard and pastes the content of the clipboard into the active window (which should be the Enhanced Editor). Test it and you will see that this is the least convenient option.

View solution in original post

6 REPLIES 6
FreelanceReinh
Jade | Level 19

Hello @hhtlib and welcome to the SAS Support Communities!

 

A couple of months ago I developed a keyboard macro for this purpose in response to another user's post and assigned a keyboard shortcut to it. Since then I've been using it myself. See https://communities.sas.com/t5/SAS-Programming/Referencing-marked-text/m-p/491164#M128748. I haven't tried yet to create a menu button for this, but in general I prefer keyboard shortcuts.

hhtlib
Calcite | Level 5

@FreelanceReinh wrote:

Hello @hhtlib and welcome to the SAS Support Communities!

 

A couple of months ago I developed a keyboard macro for this purpose in response to another user's post and assigned a keyboard shortcut to it. Since then I've been using it myself. See https://communities.sas.com/t5/SAS-Programming/Referencing-marked-text/m-p/491164#M128748. I haven't tried yet to create a menu button for this, but in general I prefer keyboard shortcuts.


 

Thanks. It's a good alternate for ctrl+/ keyboard shortcut. I am lazy and most of time just use one hand to move/click the mouse. So a button for commenting the select text would be the best. Wish we can assign same commands to a customized button like what we can do for keyboard shortcut.

 

FreelanceReinh
Jade | Level 19

@hhtlib wrote:

Thanks. It's a good alternate for ctrl+/ keyboard shortcut. I am lazy and most of time just use one hand to move/click the mouse. So a button for commenting the select text would be the best. Wish we can assign same commands to a customized button like what we can do for keyboard shortcut.

 


I see three options:

 

  1. Use a mouse with programmable additional buttons. Then you could emulate an arbitrary sequence of keystrokes by pressing a custom mouse button. That sequence of keystrokes could be either an Enhanced Editor keyboard shortcut or simply the sequence of keystrokes by which you would comment out marked text manually. I think this is the most convenient option because you don't even need to move your mouse and hit a small target area on the screen, but just click a mouse button.

  2. Create an .exe file (say cmt_out.exe) that emulates the sequence of keystrokes needed for commenting out (see above), e.g. with AutoIt, and make it available to the OS. Then create a button in the Enhanced Editor (Tools --> Customize... --> Customize --> Add tool) and associate it with the command gsubmit "%sysexec cmt_out;".

  3. If neither new hardware nor custom .exe files are allowed in your work environment, you can create a button in the Enhanced Editor (see item 2 above) and associate it with the command, say, gsubmit "%inc 'C:\Temp\cmt_out.sas';" where cmt_out.sas is a program along the lines of this:
    options nonotes nosource;
    filename _cb clipbrd;
    filename _tmp temp;
    
    dm 'wcopy';
    
    data _null_;
    infile _cb;
    file _tmp;
    input;
    put _infile_;
    run;
    
    data _null_;
    infile _tmp;
    file _cb;
    input;
    _infile_='/* '||_infile_||' */';
    put _infile_;
    run;
    
    filename _cb clear;
    filename _tmp clear;
    options notes source;
    
    dm 'wpaste';
    This program copies marked text into the Windows clipboard, reads the text from the clipboard, writes it to a temporary file, reads it from there, encloses each line in C-style comments, writes this commented text back to the clipboard and pastes the content of the clipboard into the active window (which should be the Enhanced Editor). Test it and you will see that this is the least convenient option.
hhtlib
Calcite | Level 5

Great solution. Thanks!

 

Played with AutoIt, compiled an Exe file, and works well on my personal pc. But I don't have permission to do it for my company's notebook.

 

It looks like the method of Option 3 is not stable. Some time it replaces the selected text directly to "/*  */", and sometime it pastes clipboard content without  "/*  */". Maybe I did something not carefully and will do more tests.

 

For option 3, the entire code can be added to the button directly, not necessary save to "C:\Temp\cmt_out.sas".

The command for the button can be very long, like the following:

gsubmit "options nonotes nosource;filename _cb clipbrd;filename _tmp temp;dm 'wcopy';data _null_;infile _cb;file _tmp;input;put _infile_;run;data _null_;infile _tmp;file _cb;input;_infile_='/* '||_infile_||' */';put _infile_;run;filename _cb clear;filename _tmp clear;options notes source;dm 'wpaste';"

 

ballardw
Super User

If you are using "Base" SAS or Foundation or Display Manager there is a default key combination of Ctrl-/. Highlight the lines of text and the key combination will place /* */ quotes on each line.  Shift-Ctrl-/ will uncomment such commented lines.

 

I don't use EG or any of the SAS Studio so can't make suggestions for that.

 

 

 

 

hhtlib
Calcite | Level 5

@ballardw wrote:

If you are using "Base" SAS or Foundation or Display Manager there is a default key combination of Ctrl-/. Highlight the lines of text and the key combination will place /* */ quotes on each line.  Shift-Ctrl-/ will uncomment such commented lines.

 

I don't use EG or any of the SAS Studio so can't make suggestions for that. 


 

Thanks. Wish the key stroke commands can be assigned to a button.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2264 views
  • 0 likes
  • 3 in conversation