How to customize tools and add a button for commenting out selected text in enhanced editor?
Thanks
@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:
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.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.
@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.
@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:
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.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';"
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.
@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.
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.
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.
Ready to level-up your skills? Choose your own adventure.