-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathopenproperties.sas
245 lines (178 loc) · 8.93 KB
/
openproperties.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
%macro OpenProperties(table,style=MessageBox,test=N) / des="Open properties of specified tables";
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: OpenProperties
Author: Chris Swenson
Created: 2011-10-18
Purpose: Open the properties of the specified table
Arguments: table - the table to open the properties of, defaulted to last
table
style= - whether to use the MESSAGEBOX macro or the WINDOW
statement supplied by the OpenProperties macro when there
is no argument specified, the last table exists, and
the user has copied a table name. See below for details.
test= - whether to test the macro
Usage: The OpenProperties macro can be set to a keyboard shortcut:
gsubmit '%OpenProperties;'
The macro will open the properties of the last table generated or
the copied table. If both exist, it asks the user which to open.
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
2011-10-18 CAS Created macro based on OpenTable.
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%put ;
%let test=%upcase(&TEST);
%let style=%substr(%upcase(&STYLE), 1, 1);
/********************************************************************************/
/* If the table is blank, check the clipboard */
%if "&TABLE"="" %then %do;
/* Temporarily turn off specific options */
%if &TEST ne Y %then %do;
%let user_mprint=%sysfunc(getoption(mprint));
%let user_notes=%sysfunc(getoption(notes));
%let user_erlvl=%sysfunc(getoption(%str(e)rrors));
option nomprint;
option nonotes;
option %str(e)rrors=0;
%end;
/* Manage scope and set defaults */
%local lastok lastmodt clip cber cbok asktbl wrong;
%let last=&SYSLAST;
%let lastok=%eval(%sysfunc(exist(%superq(last), %str(DATA))) + %sysfunc(exist(%superq(last), %str(VIEW))));
%let clip=;
%let cber=0;
%let cbok=0;
/****************************************************************************
Recent Table
****************************************************************************/
/* If the table is blank, check the modified date of the last table */
%if &LASTOK=1 %then %do;
%let lastmodt=%tableinfo(&LAST, MODTE);
/* Evaluate modified date of last table */
%if &LASTMODT ne . %then %do;
%if %eval( %scan(%sysfunc(datetime()), 1, %str(.)) - %sysfunc(inputn(&LASTMODT, datetime20.)) ) < 5
%then %let table=&LAST;
%end;
%end;
/****************************************************************************
Clipboard
****************************************************************************/
%if "&TABLE"="" %then %do;
/* Access clipboard */
filename _cb_ clipbrd;
/* Set clipboard value to macro variable */
/* REVISION 2011-07-26 CAS: Added processing on clipboard content */
data _null_;
infile _cb_ truncover;
input content $50.;
content=compress(content, '_.', 'kad');
rc=nvalid(scan(content, -1, '.'));
if rc=0 then do;
content='';
call symputx('clip', content);
end;
else do;
call symputx('clip', content);
end;
run;
/* Retain (e)rror variable */
%let cber=&SYSERR;
/* Clear clipboard filename */
filename _cb_ clear;
/* Set library */
%local lib;
%if %sysfunc(libref(user))=0 %then %let lib=user;
%else %let lib=work;
%let clip=%upcase(%superq(clip));
%if %sysfunc(compress(%superq(clip), %str(.), %str(k))) ne %str(.) %then %let clip=&LIB..%superq(clip);
%put NOTE: Copied value: %superq(clip);
%put NOTE: Last modified: &SYSLAST;
/* Evaluate the condition of the clipboard material */
%if (%superq(clip) ne &SYSLAST) and &CBER<4 %then %do;
%let cbok=%eval(%sysfunc(exist(%superq(clip), %str(DATA))) + %sysfunc(exist(%superq(clip), %str(VIEW))));
/* If there is a conflict, ask the user */
%if &CBOK=1 and &LASTOK=1 %then %do;
%if &STYLE=M %then %do;
%local response;
%let response=%MessageBox(
Would you like to open the properties of the copied table? Otherwise select No to open the properties of the last table.
, title=OpenProperties Question, buttons=YNC, default=1, icon=Q)
;
%if &RESPONSE=YES
%then %do;
%let table=%superq(clip);
%put NOTE: Opening properties of table from clipboard.;
%end;
%else %if &RESPONSE=NO %then %do;
%let table=&syslast;
%put NOTE: Opening properties of last table.;
%end;
%else %if &RESPONSE=CANCEL %then %goto cancel;
%end;
%else %if &STYLE=W %then %do;
%let asktbl=;
%let wrong=;
%loop:
%window asktbl
#2 @5 "&WRONG" color=red
#3 @5 "OpenProperties: Select a Table: " asktbl 1 color=blue attr=rev_video required=yes " (C=Copied, L=Last, X=Cancel)"
#5 @5 "Press ENTER to continue"
;
%display asktbl delete;
%let asktbl=%upcase(&asktbl);
%if %index(*C*L*X*,*&ASKTBL*)=0 %then %do;
%let wrong=%str(I)NVALID ENTRY;
%goto loop;
%end;
%if &asktbl=C %then %do;
%let table=%superq(clip);
%put NOTE: Opening properties of table from clipboard.;
%end;
%else %if &asktbl=L %then %do;
%let table=&syslast;
%put NOTE: Opening properties of last table.;
%end;
%else %if &ASKTBL=X %then %goto cancel;
%end;
%end;
/* If not, use clipboard or syslast */
%else %if &CBOK=1 and &LASTOK=0 %then %let table=%superq(CLIP);
%else %let table=&LAST;
%end;
%else %let table=&LAST;
%end;
%cancel:
/* Restore user options */
%if &TEST ne Y %then %do;
option %str(e)rrors=&USER_ERLVL;
option &user_mprint &USER_NOTES;
%end;
%end;
/********************************************************************************/
/* Manage macros */
%local num tbl;
/* Set initial scan */
%let num=1;
%let tbl=%scan(&TABLE, &NUM, %str( )%str(,)%str(%()%str(%)));
/* Loop through each argument until blank */
%do %while("&TBL" ne "");
/* Check if table exists */
%if %eval(%sysfunc(exist(&TBL, %str(DATA))) + %sysfunc(exist(&TBL, %str(VIEW))))=1 %then %do;
dm "VAR %sysfunc(compress(&TBL))" var;
%end;
/* Otherwise pop-up a message that it does not exist. */
%else %do;
dm 'postmessage "The specified table &TABLE does not exist."';
%end;
/* Increment scan */
%let num=%eval(&NUM+1);
%let tbl=%scan(&TABLE, &NUM, %str( )%str(,)%str(%()%str(%)));
%end;
%put ;
%mend OpenProperties;