View
220
Download
0
Category
Preview:
Citation preview
AutomagicallyCopying and Pasting
Variable Names
Arthur Tabachneck Roger DeAngelis Randy
Herbison Insurance Bureau of Canada CompuCraft Inc Westat
John King Tom Abernathy Andrew Clapson
Ouachita Clinical Data Services, Inc. Pfizer, Inc. Ottawa, Ontario
Coder’s CornerApril 12, 2010ForumSAS
Have you ever wished that SAS provided a way for you to easily develop point-and-click methods for
accomplishing common tasks?
Coder’s CornerApril 12, 2010ForumSAS
The present project began in response to a SAS-L post asking:
Is there a way to copy and paste any table’s variable names?
Coder’s CornerApril 12, 2010ForumSAS
and, of course, the task had to be accomplished almost
automagically
Coder’s CornerApril 12, 2010ForumSAS
and suppose that
you only have base SAS
but, regardless,
you’re not quite a SAS guru
you’d really like to impress the people you work with and/or make SAS easier to use
Coder’s CornerApril 12, 2010ForumSAS
how?take advantage of some not very well known
capabilities of SAS Explorer
Coder’s CornerApril 12, 2010ForumSAS
how?take advantage of some not very well known
capabilities of SAS Explorer
Coder’s CornerApril 12, 2010ForumSAS
how?
take advantage of some not very well known capabilities of SAS Explorer
Coder’s CornerApril 12, 2010ForumSAS
such a capability is only moments away with the method described in this presentation
Coder’s CornerApril 12, 2010ForumSAS
how?
Click anywhere in the SAS Explorer side of the screen
Coder’s CornerApril 12, 2010ForumSAS
how?
Click on Tools→Options→Explorer
Coder’s CornerApril 12, 2010ForumSAS
how?Click on the ‘Members’ tab, the ‘Table’ Library
Member and, finally, on the ‘Edit’ Button
Coder’s CornerApril 12, 2010ForumSAS
how?
Click on Add
Coder’s CornerApril 12, 2010ForumSAS
how?In the Explorer Options’ Action screen
type the Action you want users to see: e.g., Copy Variable &Names to Clipboard
1
Copy Variable &Names to Clipboard
Action
Copy Variable &Names to Clipboard
Coder’s CornerApril 12, 2010ForumSAS
2
how?Type the Action Command you want SAS to apply:
gsubmit "filename _cb clipbrd;data _null_;file _cb;dsn='%8b'||'.'||'%32b';length name $32;do dsid=open(dsn,'I')
while(dsid ne 0);do i = 1 to attrn(dsid,'NVARS');name = varname(dsid,i);put name @; end; dsid = close(dsid);end;run; filename _cb clear; ";
Copy Variable &Names to Clipboard
gsubmit ‘filename _cb clipbrd;data _null_
filename _cb clipbrd;data _null_; file _cb; dsn='%8b'||'.'||'%32b'; length name $32; do dsid=open(dsn,'I') while(dsid ne 0); do i = 1 to attrn(dsid,'NVARS'); name = varname(dsid,i); put name @; end; dsid = close(dsid); end;run;filename _cb clear;
Action Command
gsubmit "filename _cb clipbrd;data _null_;file _cb;dsn='%8b'||'.'||'%32b'; length name $32;do dsid=open(dsn,'I') while(dsid ne 0);do i = 1 to attrn(dsid, 'NVARS');name = varname(dsid,i);put name @; end; dsid = close(dsid);end; run; filename _cb clear; ";
Coder’s CornerApril 12, 2010ForumSAS
Copy Variable &Names to Clipboard
how?
Copy Variable &Names to Clipboard
gsubmit ‘filename _cb clipbrd;data _null_
Click on OK to exit the Add Action screen3
Coder’s CornerApril 12, 2010ForumSAS
how?
Click on OK to exit the Table Options screen4
Coder’s CornerApril 12, 2010ForumSAS
a solutionthen, whenever you or a user right-click
on a file in the SAS Explorer window
Coder’s CornerApril 12, 2010ForumSAS
then you can paste the variable names into SAS or any other program that has copy/paste functionality
The Hotkey Driven Solution
Coder’s CornerApril 12, 2010ForumSAS
The Hotkey Driven Solutionthen you can paste the variable names into SAS or any other
program that has copy/paste functionality
Coder’s CornerApril 12, 2010ForumSAS
wouldn’t it be nice to put all of your (or your users) common tasks on that menu?
Copy Variable Names to ClipboardRun Proc ContentsGet descriptive statisticsShow all correlationsCompare groupsPrint bar chartsRun factor analysis
Action command for Proc Contents
gsubmit "proc contents data=%8b.%s;run;";
Coder’s CornerApril 12, 2010ForumSAS
For those of you who wanta non-point-and-click solution
a complete just as easy to develop hotkey-driven solution is also described in our paper
Coder’s CornerApril 12, 2010ForumSAS
Type and save the following SAS program (e.g., as c:\copy.sas):1
The Hotkey Driven Solution
filename _cb clipbrd;data _null_; window DSN rows=8 columns=80 irow=1 icolumn=2 color=black #2 @3 'Enter 1 or 2 level data set name: ‘ color=gray dsn $41. required=yes attr=underline color=yellow; display DSN blank; file _cb; length name $32; do dsid = open(dsn,'I') while(dsid ne 0); do i = 1 to attrn(dsid,'NVARS'); name = varname(dsid,i); put name @; end; dsid = close(dsid); end; stop;run;filename _cb clear;
filename _cb clipbrd;data _null_; window DSN rows=8 columns=80 irow=1 icolumn=2 color=black #2 @3 'Enter 1 or 2 level data set name: ‘ color=gray dsn $41. required=yes attr=underline color=yellow; display DSN blank;
file _cb; length name $32; do dsid = open(dsn,'I') while(dsid ne 0); do i = 1 to attrn(dsid,'NVARS'); name = varname(dsid,i); put name @; end; dsid = close(dsid); end; stop;
run;
filename _cb clear;
Coder’s CornerApril 12, 2010ForumSAS
Assign a key to run the code
In command line type: keydef "CTL F11" "gsubmit '%inc ""c:\copy.sas"";' "
2
The Hotkey Driven Solution
keydef "CTL F11" "gsubmit '%inc ""c:\copy.sas"";' "
Coder’s CornerApril 12, 2010ForumSAS
Save the assigned key assignment
In command line type: keys
3
The Hotkey Driven Solution
Coder’s CornerApril 12, 2010ForumSAS
Save the assigned key assignment
In command line type: save, then click on ‘Yes’ and ‘OK’
4
The Hotkey Driven Solution
Coder’s CornerApril 12, 2010ForumSAS
Then, whenever you or a user enters the assigned key they will be asked to‘Enter 1 or 2 level data set name:’
The Hotkey Driven Solution
Coder’s CornerApril 12, 2010ForumSAS
then you can paste the variable names into SAS or any other program that has copy/paste functionality
The Hotkey Driven Solution
Coder’s CornerApril 12, 2010ForumSAS
The Hotkey Driven Solutionthen you can paste the variable names into SAS or any other
program that has copy/paste functionality
Coder’s CornerApril 12, 2010ForumSAS
Author Contact Information
Your comments and questions are valued and encouraged.
Contact the authors:Arthur Tabachneck, Ph.D.Director, Data ManagementInsurance Bureau of Canada2235 Sheppard Ave. EastToronto, Ontario L3T 5K9e-mail: atabachneck@ibc.ca
John King,Ouachita Clinical Data Services, Inc.Mount Ida, ARe-mail: ouachitaclinicaldataservices@gmail.com
Randy Herbison,Senior Systems Analyst Westat1650 Research BoulevardRockville, MD 20850e-mail: RandyHerbison@westat.com
Roger DeAngelisCompuCraft Inc1770 Via Petirrojo Apt ANewbury Park, CA 91320e-mail: xlr82sas@aol.com
Andrew Clapson Ottawa, Ontario e-mail: andy_clapson@hotmail.com
Tom AbernathyPfizer, Inc.235 E. 42nd StreetNew York, NY 10017e-mail: tom.abernathy@pfizer.com
Recommended