@sasjs/core 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mf_islibds.sas +40 -0
- package/base/mp_makedata.sas +33 -18
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Checks whether a string follows correct library.dataset format
|
|
4
|
+
@details Many macros in the core library accept a library.dataset parameter
|
|
5
|
+
referred to as 'libds'. This macro validates the structure of that parameter,
|
|
6
|
+
eg:
|
|
7
|
+
|
|
8
|
+
@li 8 character libref?
|
|
9
|
+
@li 32 character dataset?
|
|
10
|
+
@li contains a period?
|
|
11
|
+
|
|
12
|
+
It does NOT check whether the dataset exists, or if the library is assigned.
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
|
|
16
|
+
%put %mf_islibds(work.something)=1;
|
|
17
|
+
%put %mf_islibds(nolib)=0;
|
|
18
|
+
%put %mf_islibds(badlibref.ds)=0;
|
|
19
|
+
%put %mf_islibds(w.t.f)=0;
|
|
20
|
+
|
|
21
|
+
@param [in] libds The string to be checked
|
|
22
|
+
|
|
23
|
+
@return output Returns 1 if libds is valid, 0 if it is not
|
|
24
|
+
|
|
25
|
+
<h4> Related Macros </h4>
|
|
26
|
+
@li mf_islibds.test.sas
|
|
27
|
+
@li mp_validatecol.sas
|
|
28
|
+
|
|
29
|
+
@version 9.2
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mf_islibds(libds
|
|
33
|
+
)/*/STORE SOURCE*/;
|
|
34
|
+
|
|
35
|
+
%local regex;
|
|
36
|
+
%let regex=%sysfunc(prxparse(%str(/^[_a-z]\w{0,7}\.[_a-z]\w{0,31}$/i)));
|
|
37
|
+
|
|
38
|
+
%sysfunc(prxmatch(®ex,&libds))
|
|
39
|
+
|
|
40
|
+
%mend mf_islibds;
|
package/base/mp_makedata.sas
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
according to the variable types and formats.
|
|
11
11
|
|
|
12
12
|
TODO:
|
|
13
|
-
@li Respect PKs
|
|
14
|
-
@li Respect NOT NULLs
|
|
15
13
|
@li Consider dates, datetimes, times, integers etc
|
|
16
14
|
|
|
17
15
|
Usage:
|
|
@@ -27,12 +25,15 @@
|
|
|
27
25
|
);
|
|
28
26
|
%mp_makedata(work.example)
|
|
29
27
|
|
|
30
|
-
@param [in] libds The empty table in which to create data
|
|
31
|
-
@param [out] obs= (500) The number of records to create.
|
|
28
|
+
@param [in] libds The empty table (libref.dataset) in which to create data
|
|
29
|
+
@param [out] obs= (500) The maximum number of records to create. The table
|
|
30
|
+
is sorted with nodup on the primary key, so the actual number of records may
|
|
31
|
+
be lower than this.
|
|
32
32
|
|
|
33
33
|
<h4> SAS Macros </h4>
|
|
34
34
|
@li mf_getuniquename.sas
|
|
35
35
|
@li mf_getvarlen.sas
|
|
36
|
+
@li mf_islibds.sas
|
|
36
37
|
@li mf_nobs.sas
|
|
37
38
|
@li mp_getcols.sas
|
|
38
39
|
@li mp_getpk.sas
|
|
@@ -44,44 +45,58 @@
|
|
|
44
45
|
|
|
45
46
|
%macro mp_makedata(libds
|
|
46
47
|
,obs=500
|
|
48
|
+
,seed=1
|
|
47
49
|
)/*/STORE SOURCE*/;
|
|
48
50
|
|
|
49
|
-
%local ds1
|
|
51
|
+
%local ds1 ds2 lib ds pk_fields i col charvars numvars ispk;
|
|
50
52
|
|
|
51
|
-
%if %
|
|
53
|
+
%if %mf_islibds(&libds)=0 %then %do;
|
|
54
|
+
%put &sysmacroname: Invalid libds (&libds) - should be library.dataset format;
|
|
55
|
+
%return;
|
|
56
|
+
%end;
|
|
57
|
+
%else %if %mf_nobs(&libds)>0 %then %do;
|
|
52
58
|
%put &sysmacroname: &libds has data, it will not be recreated;
|
|
53
59
|
%return;
|
|
54
60
|
%end;
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
%let ds1=%mf_getuniquename(prefix=
|
|
58
|
-
%let
|
|
59
|
-
%let
|
|
60
|
-
|
|
62
|
+
/* set up temporary vars */
|
|
63
|
+
%let ds1=%mf_getuniquename(prefix=mp_makedatads1);
|
|
64
|
+
%let ds2=%mf_getuniquename(prefix=mp_makedatads2);
|
|
65
|
+
%let lib=%scan(&libds,1,.);
|
|
66
|
+
%let ds=%scan(&libds,2,.);
|
|
67
|
+
|
|
68
|
+
/* grab the primary key vars */
|
|
69
|
+
%mp_getpk(&lib,ds=&ds,outds=&ds1)
|
|
70
|
+
|
|
71
|
+
proc sql noprint;
|
|
72
|
+
select pk_fields into: pk_fields from &ds1;
|
|
73
|
+
|
|
74
|
+
data &ds2;
|
|
61
75
|
if 0 then set &libds;
|
|
62
76
|
do _n_=1 to &obs;
|
|
63
|
-
&c1=repeat(uuidgen(),10);
|
|
64
|
-
&n1=ranuni(1)*5000000;
|
|
65
|
-
drop &c1 &n1;
|
|
66
77
|
%let charvars=%mf_getvarlist(&libds,typefilter=C);
|
|
67
78
|
%if &charvars ^= %then %do i=1 %to %sysfunc(countw(&charvars));
|
|
68
79
|
%let col=%scan(&charvars,&i);
|
|
69
|
-
|
|
80
|
+
/* create random value based on observation number and colum length */
|
|
81
|
+
&col=substr(put(md5(_n_),$hex32.),1,%mf_getvarlen(&libds,&col));
|
|
70
82
|
%end;
|
|
71
83
|
|
|
72
84
|
%let numvars=%mf_getvarlist(&libds,typefilter=N);
|
|
73
85
|
%if &numvars ^= %then %do i=1 %to %sysfunc(countw(&numvars));
|
|
74
86
|
%let col=%scan(&numvars,&i);
|
|
75
|
-
&col
|
|
87
|
+
&col=_n_;
|
|
76
88
|
%end;
|
|
77
89
|
output;
|
|
78
90
|
end;
|
|
79
91
|
run;
|
|
92
|
+
proc sort data=&ds2 nodupkey;
|
|
93
|
+
by &pk_fields;
|
|
94
|
+
run;
|
|
80
95
|
|
|
81
|
-
proc append base=&libds data=&
|
|
96
|
+
proc append base=&libds data=&ds2;
|
|
82
97
|
run;
|
|
83
98
|
|
|
84
99
|
proc sql;
|
|
85
|
-
drop table &ds1;
|
|
100
|
+
drop table &ds1, &ds2;
|
|
86
101
|
|
|
87
102
|
%mend mp_makedata;
|
package/package.json
CHANGED