@sasjs/utils 2.48.2 → 2.49.1

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.
Files changed (163) hide show
  1. package/fs/generateCompileProgram.d.ts +1 -0
  2. package/fs/generateCompileProgram.js +154 -0
  3. package/fs/generateCompileProgram.js.map +1 -0
  4. package/fs/hash.d.ts +22 -0
  5. package/fs/hash.js +225 -0
  6. package/fs/hash.js.map +1 -0
  7. package/fs/index.d.ts +3 -0
  8. package/fs/index.js +13 -0
  9. package/fs/index.js.map +1 -0
  10. package/fs/internal/helper.d.ts +4 -0
  11. package/fs/internal/helper.js +125 -0
  12. package/fs/internal/helper.js.map +1 -0
  13. package/fs/sync.d.ts +6 -0
  14. package/fs/sync.js +208 -0
  15. package/fs/sync.js.map +1 -0
  16. package/index.d.ts +1 -0
  17. package/index.js +1 -0
  18. package/index.js.map +1 -1
  19. package/macros/mf_abort.sas +27 -0
  20. package/macros/mf_dedup.sas +53 -0
  21. package/macros/mf_deletefile.sas +31 -0
  22. package/macros/mf_existds.sas +30 -0
  23. package/macros/mf_existfeature.sas +59 -0
  24. package/macros/mf_existfileref.sas +33 -0
  25. package/macros/mf_existfunction.sas +37 -0
  26. package/macros/mf_existvar.sas +39 -0
  27. package/macros/mf_existvarlist.sas +56 -0
  28. package/macros/mf_fmtdttm.sas +42 -0
  29. package/macros/mf_getapploc.sas +78 -0
  30. package/macros/mf_getattrc.sas +34 -0
  31. package/macros/mf_getattrn.sas +34 -0
  32. package/macros/mf_getengine.sas +54 -0
  33. package/macros/mf_getfilesize.sas +64 -0
  34. package/macros/mf_getfmtlist.sas +61 -0
  35. package/macros/mf_getfmtname.sas +44 -0
  36. package/macros/mf_getkeyvalue.sas +32 -0
  37. package/macros/mf_getplatform.sas +75 -0
  38. package/macros/mf_getquotedstr.sas +57 -0
  39. package/macros/mf_getschema.sas +43 -0
  40. package/macros/mf_getuniquefileref.sas +60 -0
  41. package/macros/mf_getuniquelibref.sas +57 -0
  42. package/macros/mf_getuniquename.sas +22 -0
  43. package/macros/mf_getuser.sas +44 -0
  44. package/macros/mf_getvalue.sas +36 -0
  45. package/macros/mf_getvarcount.sas +49 -0
  46. package/macros/mf_getvarformat.sas +72 -0
  47. package/macros/mf_getvarlen.sas +56 -0
  48. package/macros/mf_getvarlist.sas +74 -0
  49. package/macros/mf_getvarnum.sas +58 -0
  50. package/macros/mf_getvartype.sas +52 -0
  51. package/macros/mf_getxengine.sas +43 -0
  52. package/macros/mf_increment.sas +29 -0
  53. package/macros/mf_isblank.sas +27 -0
  54. package/macros/mf_isdir.sas +34 -0
  55. package/macros/mf_isint.sas +36 -0
  56. package/macros/mf_islibds.sas +40 -0
  57. package/macros/mf_loc.sas +29 -0
  58. package/macros/mf_mkdir.sas +67 -0
  59. package/macros/mf_mval.sas +19 -0
  60. package/macros/mf_nobs.sas +26 -0
  61. package/macros/mf_trimstr.sas +50 -0
  62. package/macros/mf_uid.sas +21 -0
  63. package/macros/mf_verifymacvars.sas +72 -0
  64. package/macros/mf_wordsinstr1andstr2.sas +53 -0
  65. package/macros/mf_wordsinstr1butnotstr2.sas +54 -0
  66. package/macros/mf_writefile.sas +67 -0
  67. package/macros/mp_abort.sas +301 -0
  68. package/macros/mp_appendfile.sas +57 -0
  69. package/macros/mp_applyformats.sas +181 -0
  70. package/macros/mp_assert.sas +56 -0
  71. package/macros/mp_assertcols.sas +145 -0
  72. package/macros/mp_assertcolvals.sas +168 -0
  73. package/macros/mp_assertdsobs.sas +121 -0
  74. package/macros/mp_assertscope.sas +147 -0
  75. package/macros/mp_base64copy.sas +117 -0
  76. package/macros/mp_binarycopy.sas +79 -0
  77. package/macros/mp_chop.sas +194 -0
  78. package/macros/mp_cleancsv.sas +78 -0
  79. package/macros/mp_cntlout.sas +85 -0
  80. package/macros/mp_copyfolder.sas +84 -0
  81. package/macros/mp_coretable.sas +73 -0
  82. package/macros/mp_createconstraints.sas +70 -0
  83. package/macros/mp_createwebservice.sas +32 -0
  84. package/macros/mp_csv2ds.sas +140 -0
  85. package/macros/mp_deleteconstraints.sas +52 -0
  86. package/macros/mp_deletefolder.sas +70 -0
  87. package/macros/mp_dictionary.sas +52 -0
  88. package/macros/mp_dirlist.sas +263 -0
  89. package/macros/mp_distinctfmtvalues.sas +50 -0
  90. package/macros/mp_dropmembers.sas +46 -0
  91. package/macros/mp_ds2cards.sas +291 -0
  92. package/macros/mp_ds2csv.sas +212 -0
  93. package/macros/mp_ds2ddl.sas +30 -0
  94. package/macros/mp_ds2fmtds.sas +105 -0
  95. package/macros/mp_ds2inserts.sas +180 -0
  96. package/macros/mp_ds2md.sas +103 -0
  97. package/macros/mp_ds2squeeze.sas +120 -0
  98. package/macros/mp_dsmeta.sas +110 -0
  99. package/macros/mp_filtercheck.sas +251 -0
  100. package/macros/mp_filtergenerate.sas +105 -0
  101. package/macros/mp_filterstore.sas +254 -0
  102. package/macros/mp_filtervalidate.sas +105 -0
  103. package/macros/mp_getcols.sas +67 -0
  104. package/macros/mp_getconstraints.sas +115 -0
  105. package/macros/mp_getdbml.sas +335 -0
  106. package/macros/mp_getddl.sas +400 -0
  107. package/macros/mp_getformats.sas +124 -0
  108. package/macros/mp_getmaxvarlengths.sas +130 -0
  109. package/macros/mp_getpk.sas +281 -0
  110. package/macros/mp_gsubfile.sas +58 -0
  111. package/macros/mp_guesspk.sas +332 -0
  112. package/macros/mp_hashdataset.sas +91 -0
  113. package/macros/mp_hashdirectory.sas +162 -0
  114. package/macros/mp_include.sas +106 -0
  115. package/macros/mp_init.sas +76 -0
  116. package/macros/mp_jsonout.sas +406 -0
  117. package/macros/mp_lib2cards.sas +78 -0
  118. package/macros/mp_lib2inserts.sas +77 -0
  119. package/macros/mp_loadformat.sas +303 -0
  120. package/macros/mp_lockanytable.sas +243 -0
  121. package/macros/mp_lockfilecheck.sas +103 -0
  122. package/macros/mp_makedata.sas +107 -0
  123. package/macros/mp_md5.sas +58 -0
  124. package/macros/mp_perflog.sas +43 -0
  125. package/macros/mp_prevobs.sas +88 -0
  126. package/macros/mp_recursivejoin.sas +90 -0
  127. package/macros/mp_replace.sas +151 -0
  128. package/macros/mp_reseterror.sas +27 -0
  129. package/macros/mp_resetoption.sas +39 -0
  130. package/macros/mp_retainedkey.sas +247 -0
  131. package/macros/mp_runddl.sas +49 -0
  132. package/macros/mp_searchcols.sas +103 -0
  133. package/macros/mp_searchdata.sas +131 -0
  134. package/macros/mp_setkeyvalue.sas +55 -0
  135. package/macros/mp_sortinplace.sas +122 -0
  136. package/macros/mp_stackdiffs.sas +592 -0
  137. package/macros/mp_storediffs.sas +230 -0
  138. package/macros/mp_stprequests.sas +74 -0
  139. package/macros/mp_streamfile.sas +212 -0
  140. package/macros/mp_testjob.sas +92 -0
  141. package/macros/mp_testservice.sas +39 -0
  142. package/macros/mp_testwritespeedlibrary.sas +59 -0
  143. package/macros/mp_tree.sas +71 -0
  144. package/macros/mp_unzip.sas +90 -0
  145. package/macros/mp_updatevarlength.sas +93 -0
  146. package/macros/mp_validatecol.sas +97 -0
  147. package/macros/mp_wait4file.sas +35 -0
  148. package/macros/mp_webin.sas +59 -0
  149. package/macros/mp_zip.sas +85 -0
  150. package/package.json +5 -2
  151. package/scripts/copySASjsCore.ts +36 -0
  152. package/types/hash.d.ts +9 -0
  153. package/types/hash.js +3 -0
  154. package/types/hash.js.map +1 -0
  155. package/types/index.d.ts +1 -0
  156. package/types/index.js +1 -0
  157. package/types/index.js.map +1 -1
  158. package/utils/index.d.ts +1 -1
  159. package/utils/index.js +2 -1
  160. package/utils/index.js.map +1 -1
  161. package/utils/utils.d.ts +1 -0
  162. package/utils/utils.js +7 -1
  163. package/utils/utils.js.map +1 -1
@@ -0,0 +1,29 @@
1
+ /**
2
+ @file
3
+ @brief Returns physical location of various SAS items
4
+ @details Returns location of the PlatformObjectFramework tools
5
+ Usage:
6
+
7
+ %put %mf_loc(POF); %*location of PlatformObjectFramework tools;
8
+
9
+ @version 9.2
10
+ @author Allan Bowe
11
+ **/
12
+
13
+ %macro mf_loc(loc);
14
+ %let loc=%upcase(&loc);
15
+ %local root;
16
+
17
+ %if &loc=POF or &loc=PLATFORMOBJECTFRAMEWORK %then %do;
18
+ %let root=%substr(%sysget(SASROOT),1,%index(%sysget(SASROOT),SASFoundation)-2);
19
+ %let root=&root/SASPlatformObjectFramework/&sysver;
20
+ %put Batch tools located at: &root;
21
+ &root
22
+ %end;
23
+ %else %if &loc=VIYACONFIG %then %do;
24
+ %let root=/opt/sas/viya/config;
25
+ %put Viya Config located at: &root;
26
+ &root
27
+ %end;
28
+
29
+ %mend mf_loc;
@@ -0,0 +1,67 @@
1
+ /**
2
+ @file
3
+ @brief Creates a directory, including any intermediate directories
4
+ @details Works on windows and unix environments via dcreate function.
5
+ Usage:
6
+
7
+ %mf_mkdir(/some/path/name)
8
+
9
+
10
+ @param dir relative or absolute pathname. Unquoted.
11
+ @version 9.2
12
+
13
+ **/
14
+
15
+ %macro mf_mkdir(dir
16
+ )/*/STORE SOURCE*/;
17
+
18
+ %local lastchar child parent;
19
+
20
+ %let lastchar = %substr(&dir, %length(&dir));
21
+ %if (%bquote(&lastchar) eq %str(:)) %then %do;
22
+ /* Cannot create drive mappings */
23
+ %return;
24
+ %end;
25
+
26
+ %if (%bquote(&lastchar)=%str(/)) or (%bquote(&lastchar)=%str(\)) %then %do;
27
+ /* last char is a slash */
28
+ %if (%length(&dir) eq 1) %then %do;
29
+ /* one single slash - root location is assumed to exist */
30
+ %return;
31
+ %end;
32
+ %else %do;
33
+ /* strip last slash */
34
+ %let dir = %substr(&dir, 1, %length(&dir)-1);
35
+ %end;
36
+ %end;
37
+
38
+ %if (%sysfunc(fileexist(%bquote(&dir))) = 0) %then %do;
39
+ /* directory does not exist so prepare to create */
40
+ /* first get the childmost directory */
41
+ %let child = %scan(&dir, -1, %str(/\:));
42
+
43
+ /*
44
+ If child name = path name then there are no parents to create. Else
45
+ they must be recursively scanned.
46
+ */
47
+
48
+ %if (%length(&dir) gt %length(&child)) %then %do;
49
+ %let parent = %substr(&dir, 1, %length(&dir)-%length(&child));
50
+ %mf_mkdir(&parent)
51
+ %end;
52
+
53
+ /*
54
+ Now create the directory. Complain loudly of any errs.
55
+ */
56
+
57
+ %let dname = %sysfunc(dcreate(&child, &parent));
58
+ %if (%bquote(&dname) eq ) %then %do;
59
+ %put %str(ERR)OR: could not create &parent + &child;
60
+ %abort cancel;
61
+ %end;
62
+ %else %do;
63
+ %put Directory created: &dir;
64
+ %end;
65
+ %end;
66
+ /* exit quietly if directory did exist.*/
67
+ %mend mf_mkdir;
@@ -0,0 +1,19 @@
1
+ /**
2
+ @file mf_mval.sas
3
+ @brief Returns a macro variable value if the variable exists
4
+ @details
5
+ Use this macro to avoid repetitive use of `%if %symexist(MACVAR) %then`
6
+ type logic.
7
+ Usage:
8
+
9
+ %if %mf_mval(maynotexist)=itdid %then %do;
10
+
11
+ @version 9.2
12
+ @author Allan Bowe
13
+ **/
14
+
15
+ %macro mf_mval(var);
16
+ %if %symexist(&var) %then %do;
17
+ %superq(&var)
18
+ %end;
19
+ %mend mf_mval;
@@ -0,0 +1,26 @@
1
+ /**
2
+ @file
3
+ @brief Returns number of logical (undeleted) observations.
4
+ @details Beware - will not work on external database tables!
5
+ Is just a convenience macro for calling <code> %mf_getattrn()</code>.
6
+
7
+ %put Number of observations=%mf_nobs(sashelp.class);
8
+
9
+ <h4> SAS Macros </h4>
10
+ @li mf_getattrn.sas
11
+
12
+ @param libds library.dataset
13
+
14
+ @return output returns result of the attrn value supplied, or log message
15
+ if err.
16
+
17
+
18
+ @version 9.2
19
+ @author Allan Bowe
20
+
21
+ **/
22
+
23
+ %macro mf_nobs(libds
24
+ )/*/STORE SOURCE*/;
25
+ %mf_getattrn(&libds,NLOBS)
26
+ %mend mf_nobs;
@@ -0,0 +1,50 @@
1
+ /**
2
+ @file mf_trimstr.sas
3
+ @brief Removes character(s) from the end, if they exist
4
+ @details If the designated characters exist at the end of the string, they
5
+ are removed
6
+
7
+ %put %mf_trimstr(/blah/,/); * /blah;
8
+ %put %mf_trimstr(/blah/,h); * /blah/;
9
+ %put %mf_trimstr(/blah/,h/);* /bla;
10
+
11
+ <h4> SAS Macros </h4>
12
+
13
+
14
+ @param basestr The string to be modified
15
+ @param trimstr The string to be removed from the end of `basestr`, if it
16
+ exists
17
+
18
+ @return output returns result with the value of `trimstr` removed from the end
19
+
20
+
21
+ @version 9.2
22
+ @author Allan Bowe
23
+
24
+ **/
25
+
26
+ %macro mf_trimstr(basestr,trimstr);
27
+ %local baselen trimlen trimval;
28
+
29
+ /* return if basestr is shorter than trimstr (or 0) */
30
+ %let baselen=%length(%superq(basestr));
31
+ %let trimlen=%length(%superq(trimstr));
32
+ %if &baselen < &trimlen or &baselen=0 %then %return;
33
+
34
+ /* obtain the characters from the end of basestr */
35
+ %let trimval=%qsubstr(%superq(basestr)
36
+ ,%length(%superq(basestr))-&trimlen+1
37
+ ,&trimlen);
38
+
39
+ /* compare and if matching, chop it off! */
40
+ %if %superq(basestr)=%superq(trimstr) %then %do;
41
+ %return;
42
+ %end;
43
+ %else %if %superq(trimval)=%superq(trimstr) %then %do;
44
+ %qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
45
+ %end;
46
+ %else %do;
47
+ &basestr
48
+ %end;
49
+
50
+ %mend mf_trimstr;
@@ -0,0 +1,21 @@
1
+ /**
2
+ @file
3
+ @brief Creates a unique ID based on system time in friendly format
4
+ @details format = YYYYMMDD_HHMMSSmmm_<sysjobid>_<3randomDigits>
5
+
6
+ %put %mf_uid();
7
+
8
+ @version 9.3
9
+ @author Allan Bowe
10
+
11
+ **/
12
+
13
+ %macro mf_uid(
14
+ )/*/STORE SOURCE*/;
15
+ %local today now;
16
+ %let today=%sysfunc(today(),yymmddn8.);
17
+ %let now=%sysfunc(compress(%sysfunc(time(),tod12.3),:.));
18
+
19
+ &today._&now._&sysjobid._%sysevalf(%sysfunc(ranuni(0))*999,CEIL)
20
+
21
+ %mend mf_uid;
@@ -0,0 +1,72 @@
1
+ /**
2
+ @file
3
+ @brief Checks if a set of macro variables exist AND contain values.
4
+ @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort.
5
+ Usage:
6
+
7
+ %let var1=x;
8
+ %let var2=y;
9
+ %put %mf_verifymacvars(var1 var2);
10
+
11
+ Returns:
12
+ > 1
13
+
14
+ <h4> SAS Macros </h4>
15
+ @li mf_abort.sas
16
+
17
+ @param [in] verifyvars Space separated list of macro variable names
18
+ @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to
19
+ uppercase.
20
+ @param [in] mAbort= (SOFT) Abort Type. When SOFT, simply writes an err
21
+ message to the log.
22
+ Set to any other value to call mf_abort (which can be configured to abort in
23
+ various fashions according to context).
24
+
25
+ @warning will not be able to verify the following variables due to
26
+ naming clash!
27
+ - verifyVars
28
+ - verifyVar
29
+ - verifyIterator
30
+ - makeUpcase
31
+
32
+ @version 9.2
33
+ @author Allan Bowe
34
+
35
+ **/
36
+
37
+
38
+ %macro mf_verifymacvars(
39
+ verifyVars /* list of macro variable NAMES */
40
+ ,makeUpcase=NO /* set to YES to make all the variable VALUES uppercase */
41
+ ,mAbort=SOFT
42
+ )/*/STORE SOURCE*/;
43
+
44
+ %local verifyIterator verifyVar abortmsg;
45
+ %do verifyIterator=1 %to %sysfunc(countw(&verifyVars,%str( )));
46
+ %let verifyVar=%qscan(&verifyVars,&verifyIterator,%str( ));
47
+ %if not %symexist(&verifyvar) %then %do;
48
+ %let abortmsg= Variable &verifyVar is MISSING;
49
+ %goto exit_err;
50
+ %end;
51
+ %if %length(%trim(&&&verifyVar))=0 %then %do;
52
+ %let abortmsg= Variable &verifyVar is EMPTY;
53
+ %goto exit_err;
54
+ %end;
55
+ %if &makeupcase=YES %then %do;
56
+ %let &verifyVar=%upcase(&&&verifyvar);
57
+ %end;
58
+ %end;
59
+
60
+ %goto exit_success;
61
+ %exit_err:
62
+ %put &abortmsg;
63
+ %mf_abort(iftrue=(&mabort ne SOFT),
64
+ mac=mf_verifymacvars,
65
+ msg=%str(&abortmsg)
66
+ )
67
+ 0
68
+ %return;
69
+ %exit_success:
70
+ 1
71
+
72
+ %mend mf_verifymacvars;
@@ -0,0 +1,53 @@
1
+ /**
2
+ @file
3
+ @brief Returns words that are in both string 1 and string 2
4
+ @details Compares two space separated strings and returns the words that are
5
+ in both.
6
+ Usage:
7
+
8
+ %put %mf_wordsInStr1andStr2(
9
+ Str1=blah sss blaaah brah bram boo
10
+ ,Str2= blah blaaah brah ssss
11
+ );
12
+
13
+ returns:
14
+ > blah blaaah brah
15
+
16
+ @param str1= string containing words to extract
17
+ @param str2= used to compare with the extract string
18
+
19
+ @warning CASE SENSITIVE!
20
+
21
+ @version 9.2
22
+ @author Allan Bowe
23
+
24
+ **/
25
+
26
+ %macro mf_wordsInStr1andStr2(
27
+ Str1= /* string containing words to extract */
28
+ ,Str2= /* used to compare with the extract string */
29
+ )/*/STORE SOURCE*/;
30
+
31
+ %local count_base count_extr i i2 extr_word base_word match outvar;
32
+ %if %length(&str1)=0 or %length(&str2)=0 %then %do;
33
+ %put base string (str1)= &str1;
34
+ %put compare string (str2) = &str2;
35
+ %return;
36
+ %end;
37
+ %let count_base=%sysfunc(countw(&Str2));
38
+ %let count_extr=%sysfunc(countw(&Str1));
39
+
40
+ %do i=1 %to &count_extr;
41
+ %let extr_word=%scan(&Str1,&i,%str( ));
42
+ %let match=0;
43
+ %do i2=1 %to &count_base;
44
+ %let base_word=%scan(&Str2,&i2,%str( ));
45
+ %if &extr_word=&base_word %then %let match=1;
46
+ %end;
47
+ %if &match=1 %then %let outvar=&outvar &extr_word;
48
+ %end;
49
+
50
+ &outvar
51
+
52
+ %mend mf_wordsInStr1andStr2;
53
+
@@ -0,0 +1,54 @@
1
+ /**
2
+ @file
3
+ @brief Returns words that are in string 1 but not in string 2
4
+ @details Compares two space separated strings and returns the words that are
5
+ in the first but not in the second.
6
+
7
+ Note - case sensitive!
8
+
9
+ Usage:
10
+
11
+ %let x= %mf_wordsInStr1ButNotStr2(
12
+ Str1=blah sss blaaah brah bram boo
13
+ ,Str2= blah blaaah brah ssss
14
+ );
15
+
16
+ returns:
17
+ > sss bram boo
18
+
19
+ @param [in] str1= string containing words to extract
20
+ @param [in] str2= used to compare with the extract string
21
+
22
+ @version 9.2
23
+ @author Allan Bowe
24
+
25
+ **/
26
+
27
+ %macro mf_wordsInStr1ButNotStr2(
28
+ Str1= /* string containing words to extract */
29
+ ,Str2= /* used to compare with the extract string */
30
+ )/*/STORE SOURCE*/;
31
+
32
+ %local count_base count_extr i i2 extr_word base_word match outvar;
33
+ %if %length(&str1)=0 or %length(&str2)=0 %then %do;
34
+ %put base string (str1)= &str1;
35
+ %put compare string (str2) = &str2;
36
+ %return;
37
+ %end;
38
+ %let count_base=%sysfunc(countw(&Str2));
39
+ %let count_extr=%sysfunc(countw(&Str1));
40
+
41
+ %do i=1 %to &count_extr;
42
+ %let extr_word=%scan(&Str1,&i,%str( ));
43
+ %let match=0;
44
+ %do i2=1 %to &count_base;
45
+ %let base_word=%scan(&Str2,&i2,%str( ));
46
+ %if &extr_word=&base_word %then %let match=1;
47
+ %end;
48
+ %if &match=0 %then %let outvar=&outvar &extr_word;
49
+ %end;
50
+
51
+ &outvar
52
+
53
+ %mend mf_wordsInStr1ButNotStr2;
54
+
@@ -0,0 +1,67 @@
1
+ /**
2
+ @file
3
+ @brief Creates a text file using pure macro
4
+ @details Creates a text file of up to 10 lines. If further lines are
5
+ desired, feel free to [create an issue](
6
+ https://github.com/sasjs/core/issues/new), or make a pull request!
7
+
8
+ The use of PARMBUFF was considered for this macro, but it would have made
9
+ things problematic for writing lines containing commas.
10
+
11
+ Usage:
12
+
13
+ %mf_writefile(&sasjswork/myfile.txt,l1=some content,l2=more content)
14
+ data _null_;
15
+ infile "&sasjswork/myfile.txt";
16
+ input;
17
+ list;
18
+ run;
19
+
20
+ @param [in] fpath Full path to file to be created or appended to
21
+ @param [in] mode= (O) Available options are A or O as follows:
22
+ @li A APPEND mode, writes new records after the current end of the file.
23
+ @li O OUTPUT mode, writes new records from the beginning of the file.
24
+ @param [in] l1= First line
25
+ @param [in] l2= Second line (etc through to l10)
26
+
27
+ <h4> Related Macros </h4>
28
+ @li mf_writefile.test.sas
29
+
30
+ @version 9.2
31
+ @author Allan Bowe
32
+ **/
33
+ /** @cond */
34
+
35
+ %macro mf_writefile(fpath,mode=O,l1=,l2=,l3=,l4=,l5=,l6=,l7=,l8=,l9=,l10=
36
+ )/*/STORE SOURCE*/;
37
+ %local fref rc fid i total_lines;
38
+
39
+ /* find number of lines by reference to first non-blank param */
40
+ %do i=10 %to 1 %by -1;
41
+ %if %str(&&l&i) ne %str() %then %goto continue;
42
+ %end;
43
+ %continue:
44
+ %let total_lines=&i;
45
+
46
+ %if %sysfunc(filename(fref,&fpath)) ne 0 %then %do;
47
+ %put &=fref &=fpath;
48
+ %put %str(ERR)OR: %sysfunc(sysmsg());
49
+ %return;
50
+ %end;
51
+
52
+ %let fid=%sysfunc(fopen(&fref,&mode));
53
+
54
+ %if &fid=0 %then %do;
55
+ %put %str(ERR)OR: %sysfunc(sysmsg());
56
+ %return;
57
+ %end;
58
+
59
+ %do i=1 %to &total_lines;
60
+ %let rc=%sysfunc(fput(&fid, &&l&i));
61
+ %let rc=%sysfunc(fwrite(&fid));
62
+ %end;
63
+ %let rc=%sysfunc(fclose(&fid));
64
+ %let rc=%sysfunc(filename(&fref));
65
+
66
+ %mend mf_writefile;
67
+ /** @endcond */