@sasjs/core 4.0.0 → 4.1.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_dedup.sas CHANGED
@@ -23,7 +23,6 @@
23
23
 
24
24
  <h4> Related Macros </h4>
25
25
  @li mf_trimstr.sas
26
- @li mf_wordsinstr1butnotstr2.sas
27
26
 
28
27
  @version 9.2
29
28
  @author Allan Bowe
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  @file
3
3
  @brief Checks if a variable exists in a data set.
4
- @details Returns 0 if the variable does NOT exist, and return the position of
5
- the var if it does.
6
- Usage:
4
+ @details Returns 0 if the variable does NOT exist, and the position of the var
5
+ if it does.
6
+ Usage:
7
7
 
8
- %put %mf_existvar(work.someds, somevar)
8
+ %put %mf_existvar(work.someds, somevar)
9
9
 
10
10
  @param [in] libds 2 part dataset or view reference
11
11
  @param [in] var variable name
@@ -5,18 +5,19 @@
5
5
 
6
6
  %put %mf_getfilesize(fpath=C:\temp\myfile.txt);
7
7
 
8
- or
8
+ or, provide a libds value as follows:
9
9
 
10
10
  data x;do x=1 to 100000;y=x;output;end;run;
11
11
  %put %mf_getfilesize(libds=work.x,format=yes);
12
12
 
13
- gives:
13
+ Which gives:
14
14
 
15
- 2mb
15
+ > 2mb
16
+
17
+ @param [in] fpath= Full path and filename. Provide this OR the libds value.
18
+ @param [in] libds= (0) Library.dataset value (assumes library is BASE engine)
19
+ @param [in] format= (NO) Set to yes to apply sizekmg. format
16
20
 
17
- @param fpath= full path and filename. Provide this OR the libds value.
18
- @param libds= library.dataset value (assumes library is BASE engine)
19
- @param format= set to yes to apply sizekmg. format
20
21
  @returns bytes
21
22
 
22
23
  @version 9.2
@@ -26,16 +27,32 @@
26
27
  %macro mf_getfilesize(fpath=,libds=0,format=NO
27
28
  )/*/STORE SOURCE*/;
28
29
 
30
+ %local rc fid fref bytes dsid lib vnum;
31
+
29
32
  %if &libds ne 0 %then %do;
30
- %let fpath=%sysfunc(pathname(%scan(&libds,1,.)))/%scan(&libds,2,.).sas7bdat;
33
+ %let libds=%upcase(&libds);
34
+ %if %index(&libds,.)=0 %then %let lib=WORK;
35
+ %else %let lib=%scan(&libds,1,.);
36
+ %let dsid=%sysfunc(open(
37
+ sashelp.vtable(where=(libname="&lib" and memname="%scan(&libds,-1,.)")
38
+ keep=libname memname filesize
39
+ )
40
+ ));
41
+ %if (&dsid ^= 0) %then %do;
42
+ %let vnum=%sysfunc(varnum(&dsid,FILESIZE));
43
+ %let rc=%sysfunc(fetch(&dsid));
44
+ %let bytes=%sysfunc(getvarn(&dsid,&vnum));
45
+ %let rc= %sysfunc(close(&dsid));
46
+ %end;
47
+ %else %put &sysmacroname: &libds could not be opened! %sysfunc(sysmsg());
48
+ %end;
49
+ %else %do;
50
+ %let rc=%sysfunc(filename(fref,&fpath));
51
+ %let fid=%sysfunc(fopen(&fref));
52
+ %let bytes=%sysfunc(finfo(&fid,File Size (bytes)));
53
+ %let rc=%sysfunc(fclose(&fid));
54
+ %let rc=%sysfunc(filename(fref));
31
55
  %end;
32
-
33
- %local rc fid fref bytes;
34
- %let rc=%sysfunc(filename(fref,&fpath));
35
- %let fid=%sysfunc(fopen(&fref));
36
- %let bytes=%sysfunc(finfo(&fid,File Size (bytes)));
37
- %let rc=%sysfunc(fclose(&fid));
38
- %let rc=%sysfunc(filename(fref));
39
56
 
40
57
  %if &format=NO %then %do;
41
58
  &bytes
@@ -30,7 +30,6 @@
30
30
 
31
31
  %local count_base count_extr i i2 extr_word base_word match outvar;
32
32
  %if %length(&str1)=0 or %length(&str2)=0 %then %do;
33
- %put %str(WARN)ING: empty string provided!;
34
33
  %put base string (str1)= &str1;
35
34
  %put compare string (str2) = &str2;
36
35
  %return;
@@ -3,6 +3,9 @@
3
3
  @brief Returns words that are in string 1 but not in string 2
4
4
  @details Compares two space separated strings and returns the words that are
5
5
  in the first but not in the second.
6
+
7
+ Note - case sensitive!
8
+
6
9
  Usage:
7
10
 
8
11
  %let x= %mf_wordsInStr1ButNotStr2(
@@ -13,10 +16,8 @@
13
16
  returns:
14
17
  > sss bram boo
15
18
 
16
- @param str1= string containing words to extract
17
- @param str2= used to compare with the extract string
18
-
19
- @warning CASE SENSITIVE!
19
+ @param [in] str1= string containing words to extract
20
+ @param [in] str2= used to compare with the extract string
20
21
 
21
22
  @version 9.2
22
23
  @author Allan Bowe
@@ -30,7 +31,6 @@
30
31
 
31
32
  %local count_base count_extr i i2 extr_word base_word match outvar;
32
33
  %if %length(&str1)=0 or %length(&str2)=0 %then %do;
33
- %put %str(WARN)ING: empty string provided!;
34
34
  %put base string (str1)= &str1;
35
35
  %put compare string (str2) = &str2;
36
36
  %return;
@@ -12,10 +12,6 @@
12
12
 
13
13
  %mp_assertdsobs(sashelp.class,test=ATMOST 20) %* pass if <21 obs present;
14
14
 
15
- <h4> SAS Macros </h4>
16
- @li mf_nobs.sas
17
- @li mp_abort.sas
18
-
19
15
 
20
16
  @param [in] inds input dataset to test for presence of observations
21
17
  @param [in] desc= (Testing observations) The user provided test description
@@ -33,6 +29,11 @@
33
29
  |---|---|---|
34
30
  |User Provided description|PASS|Dataset &inds has XX obs|
35
31
 
32
+ <h4> SAS Macros </h4>
33
+ @li mf_getuniquename.sas
34
+ @li mf_nobs.sas
35
+ @li mp_abort.sas
36
+
36
37
  <h4> Related Macros </h4>
37
38
  @li mp_assertcolvals.sas
38
39
  @li mp_assert.sas
@@ -49,9 +50,10 @@
49
50
  outds=work.test_results
50
51
  )/*/STORE SOURCE*/;
51
52
 
52
- %local nobs;
53
+ %local nobs ds;
53
54
  %let nobs=%mf_nobs(&inds);
54
55
  %let test=%upcase(&test);
56
+ %let ds=%mf_getuniquename(prefix=mp_assertdsobs);
55
57
 
56
58
  %if %substr(&test.xxxxx,1,6)=EQUALS %then %do;
57
59
  %let val=%scan(&test,2,%str( ));
@@ -84,7 +86,7 @@
84
86
  )
85
87
  %end;
86
88
 
87
- data;
89
+ data &ds;
88
90
  length test_description $256 test_result $4 test_comments $256;
89
91
  test_description=symget('desc');
90
92
  test_result='FAIL';
@@ -110,9 +112,6 @@
110
112
  %end;
111
113
  run;
112
114
 
113
- %local ds;
114
- %let ds=&syslast;
115
-
116
115
  proc append base=&outds data=&ds;
117
116
  run;
118
117
 
@@ -1,18 +1,25 @@
1
1
  /**
2
2
  @file
3
3
  @brief Used to capture scope leakage of macro variables
4
- @details A common 'difficult to detect' bug in macros is where a nested
5
- macro over-writes variables in a higher level macro.
4
+ @details
6
5
 
7
- This assertion takes a snapshot of the macro variables before and after
8
- a macro invocation. This makes it easy to detect whether any macro
9
- variables were modified or changed.
6
+ A common 'difficult to detect' bug in macros is where a nested macro
7
+ over-writes variables in a higher level macro.
10
8
 
11
- Currently, the macro only checks for global scope variables. In the future
12
- it may be extended to work at multiple levels of nesting.
9
+ This assertion takes a snapshot of the macro variables before and after
10
+ a macro invocation. Differences are captured in the `&outds` table. This
11
+ makes it easy to detect whether any macro variables were modified or
12
+ changed.
13
13
 
14
- If you would like this feature, feel free to contribute / raise an issue /
15
- engage the SASjs team directly.
14
+ The following variables are NOT tested (as they are known, global variables
15
+ used in SASjs):
16
+
17
+ @li &sasjs_prefix._FUNCTIONS
18
+
19
+ Global variables are initialised in mp_init.sas - which will also trigger
20
+ "strict mode" in your SAS session. Whilst this is a default in SASjs
21
+ produced apps, if you prefer not to use this mode, simply instantiate the
22
+ following variable to prevent the macro from running: `SASJS_PREFIX`
16
23
 
17
24
  Example usage:
18
25
 
@@ -24,12 +31,17 @@
24
31
  desc=Checking macro variables against previous snapshot
25
32
  )
26
33
 
34
+ This macro is designed to work alongside `sasjs test` - for more information
35
+ about this facility, visit [cli.sasjs.io/test](https://cli.sasjs.io/test).
36
+
27
37
  @param [in] action (SNAPSHOT) The action to take. Valid values:
28
38
  @li SNAPSHOT - take a copy of the current macro variables
29
39
  @li COMPARE - compare the current macro variables against previous values
30
40
  @param [in] scope= (GLOBAL) The scope of the variables to be checked. This
31
41
  corresponds to the values in the SCOPE column in `sashelp.vmacro`.
32
42
  @param [in] desc= (Testing scope leakage) The user provided test description
43
+ @param [in] ignorelist= Provide a list of macro variable names to ignore from
44
+ the comparison
33
45
  @param [in,out] scopeds= (work.mp_assertscope) The dataset to contain the
34
46
  scope snapshot
35
47
  @param [out] outds= (work.test_results) The output dataset to contain the
@@ -38,6 +50,10 @@
38
50
  |---|---|---|
39
51
  |User Provided description|PASS|No out of scope variables created or modified|
40
52
 
53
+ <h4> SAS Macros </h4>
54
+ @li mf_getquotedstr.sas
55
+ @li mp_init.sas
56
+
41
57
  <h4> Related Macros </h4>
42
58
  @li mp_assert.sas
43
59
  @li mp_assertcols.sas
@@ -54,9 +70,18 @@
54
70
  desc=Testing Scope Leakage,
55
71
  scope=GLOBAL,
56
72
  scopeds=work.mp_assertscope,
73
+ ignorelist=,
57
74
  outds=work.test_results
58
75
  )/*/STORE SOURCE*/;
59
- %local ds test_result test_comments del add mod;
76
+ %local ds test_result test_comments del add mod ilist;
77
+ %let ilist=%upcase(&sasjs_prefix._FUNCTIONS &ignorelist);
78
+
79
+ /**
80
+ * this sets up the global vars, it will also enter STRICT mode. If this
81
+ * behaviour is not desired, simply initiate the following global macro
82
+ * variable to prevent the macro from running: SASJS_PREFIX
83
+ */
84
+ %mp_init()
60
85
 
61
86
  /* get current variables */
62
87
  %if &action=SNAPSHOT %then %do;
@@ -64,7 +89,7 @@
64
89
  create table &scopeds as
65
90
  select name,offset,value
66
91
  from dictionary.macros
67
- where scope="&scope"
92
+ where scope="&scope" and name not in (%mf_getquotedstr(&ilist))
68
93
  order by name,offset;
69
94
  %end;
70
95
  %else %if &action=COMPARE %then %do;
@@ -73,7 +98,7 @@
73
98
  create table _data_ as
74
99
  select name,offset,value
75
100
  from dictionary.macros
76
- where scope="&scope"
101
+ where scope="&scope" and name not in (%mf_getquotedstr(&ilist))
77
102
  order by name,offset;
78
103
 
79
104
  %let ds=&syslast;
@@ -10,6 +10,8 @@
10
10
  %mp_coretable(LOCKTABLE,libds=work.locktable)
11
11
 
12
12
  @param [in] table_ref The type of table to create. Example values:
13
+ @li DIFFTABLE - Used to store changes to tables. Used by mp_storediffs.sas
14
+ and mp_stackdiffs.sas
13
15
  @li FILTER_DETAIL - For storing detailed filter values. Used by
14
16
  mp_filterstore.sas.
15
17
  @li FILTER_SUMMARY - For storing summary filter values. Used by
@@ -25,6 +27,8 @@
25
27
  @li mp_filterstore.sas
26
28
  @li mp_lockanytable.sas
27
29
  @li mp_retainedkey.sas
30
+ @li mp_storediffs.sas
31
+ @li mp_stackdiffs.sas
28
32
 
29
33
  @version 9.2
30
34
  @author Allan Bowe
@@ -36,7 +40,29 @@
36
40
  %local outds ;
37
41
  %let outds=%sysfunc(ifc(&libds=0,_data_,&libds));
38
42
  proc sql;
39
- %if &table_ref=LOCKTABLE %then %do;
43
+ %if &table_ref=DIFFTABLE %then %do;
44
+ create table &outds(
45
+ load_ref char(36) label='unique load reference',
46
+ processed_dttm num format=E8601DT26.6 label='Processed at timestamp',
47
+ libref char(8) label='Library Reference (8 chars)',
48
+ dsn char(32) label='Dataset Name (32 chars)',
49
+ key_hash char(32) label=
50
+ 'MD5 Hash of primary key values (pipe seperated)',
51
+ move_type char(1) label='Either (A)ppended, (D)eleted or (M)odified',
52
+ is_pk num label='Is Primary Key Field? (1/0)',
53
+ is_diff num label=
54
+ 'Did value change? (1/0/-1). Always -1 for appends and deletes.',
55
+ tgtvar_type char(1) label='Either (C)haracter or (N)umeric',
56
+ tgtvar_nm char(32) label='Target variable name (32 chars)',
57
+ oldval_num num format=best32. label='Old (numeric) value',
58
+ newval_num num format=best32. label='New (numeric) value',
59
+ oldval_char char(32765) label='Old (character) value',
60
+ newval_char char(32765) label='New (character) value',
61
+ constraint pk_mpe_audit
62
+ primary key(load_ref,libref,dsn,key_hash,tgtvar_nm)
63
+ );
64
+ %end;
65
+ %else %if &table_ref=LOCKTABLE %then %do;
40
66
  create table &outds(
41
67
  lock_lib char(8),
42
68
  lock_ds char(32),
@@ -49,10 +49,6 @@
49
49
  ,mac=&sysmacroname
50
50
  ,msg=%str(the BASEDS variable must be provided)
51
51
  )
52
- %mp_abort(iftrue=( &baseds=0 )
53
- ,mac=&sysmacroname
54
- ,msg=%str(the BASEDS variable must be provided)
55
- )
56
52
  %mp_abort(iftrue=( %mf_existds(&baseds)=0 )
57
53
  ,mac=&sysmacroname
58
54
  ,msg=%str(the BASEDS dataset (&baseds) needs to be assigned, and to exist)
@@ -49,7 +49,7 @@
49
49
 
50
50
  %macro mp_ds2squeeze(
51
51
  libds,
52
- outds=work.work.mp_ds2squeeze,
52
+ outds=work.mp_ds2squeeze,
53
53
  mdebug=0
54
54
  )/*/STORE SOURCE*/;
55
55
  %local dbg source;
@@ -62,9 +62,10 @@
62
62
  %let source=/source2;
63
63
  %end;
64
64
 
65
- %local optval ds fref;
65
+ %local optval ds fref startsize;
66
66
  %let ds=%mf_getuniquename();
67
67
  %let fref=%mf_getuniquefileref();
68
+ %let startsize=%mf_getfilesize(libds=&libds,format=yes);
68
69
 
69
70
  %mp_getmaxvarlengths(&libds,outds=&ds)
70
71
 
@@ -113,7 +114,7 @@ options varlenchk=&optval;
113
114
  filename &fref clear;
114
115
  %end;
115
116
 
116
- %put &sysmacroname: &libds was %mf_getfilesize(libds=&libds,format=yes);
117
+ %put &sysmacroname: &libds was &startsize;
117
118
  %put &sysmacroname: &outds is %mf_getfilesize(libds=&outds,format=yes);
118
119
 
119
120
  %mend mp_ds2squeeze;