-
Notifications
You must be signed in to change notification settings - Fork 0
/
varstoonecasesize.sas
116 lines (93 loc) · 2.12 KB
/
varstoonecasesize.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
/* varstoonecasesize.sas */
/*
The %VarsToOneCaseSize() macro requires:
the BasePlus(at least 1.43.0) package and
the macroArray package.
%loadPackageS(BasePlus(1.43.0), macroArray)
%helpPackage(basePlus, '%getVars()')
%helpPackage(macroArray, '%do_over()')
%helpPackage(macroArray, '%deleteMacArray()')
*/
%macro VarsToOneCaseSize(
lib
,ds
,case=L /* L U */
) / minoperator;
%if %sysfunc(exist(&lib..&ds.)) %then
%do;
%local pattern;
/*%put **&case.**;*/
%if %superq(case) IN (u U) %then
%do;
%let case=UPCASE;
%let pattern=[a-z]+;
%end;
%else
%do;
%let case=lowcase;
%let pattern=[A-Z]+;
%end;
/*%put **&case.**&pattern.**;*/
%getVars(&lib..&ds.,mcArray=___vars,pattern=&pattern.,ignoreCases=0)
%if %SYMGLOBL(___varsN) %then
%do;
%if &___varsN. %then
%do;
PROC DATASETS LIB=&lib. NOLIST NOWARN;
MODIFY &ds.;
RENAME
%do_over(___vars,phrase=%nrstr(
%___vars(&_I_.)=%&case.(%___vars(&_I_.))
))
;;;;
RUN;
QUIT;
%end;
%end;
%deleteMacArray(___vars, macarray=Y)
%end;
%mend VarsToOneCaseSize;
data class;
set sashelp.class;
run;
proc print data=class(obs=3);
run;
options mprint;
%VarsToOneCaseSize(work,class) /* all to lowcase */
proc print data=class(obs=3);
run;
options mprint;
%VarsToOneCaseSize(work,class) /* no update done */
proc print data=class(obs=3);
run;
options mprint;
%VarsToOneCaseSize(work,class,case=U) /* all to upcase */
proc print data=class(obs=3);
run;
/*###################################################*/
/* Macro above overcome the following issue too */
/*
options nofullstimer;
resetline;
data test;
a=42;
run;
PROC DATASETS LIB=work NOLIST NOWARN;
MODIFY test;
RENAME
a=a %* keep lower case - gives an error ;
;;;;
RUN;
QUIT;
PROC DATASETS LIB=work NOLIST NOWARN;
MODIFY test;
RENAME
a=A %* change to upper case - no error ;
;;;;
RUN;
QUIT;
data test2;
set test;
rename a=a; %* no error in data step ;
run;
*/