Skip to content

Commit c72e1aa

Browse files
committed
Cleanup and more parameter checks
1 parent 6accbc7 commit c72e1aa

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

macros/read_datasetjson.sas

+22-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@
3838
%goto exit_macro;
3939
%end;
4040

41-
%* Spoecify either jsonpath or jsonfref;
41+
%* Specify either jsonpath or jsonfref;
4242
%if %sysevalf(%superq(jsonpath)=, boolean) and %sysevalf(%superq(jsonfref)=, boolean) %then %do;
4343
%put ERR%str(OR): [&sysmacroname] Both jsonpath and jsonfref are missing. Specify one of them.;
4444
%goto exit_macro;
4545
%end;
4646

47-
48-
%* Spoecify either jsonpath or jsonfref;
47+
%* Specify either jsonpath or jsonfref;
4948
%if %sysevalf(%superq(jsonpath)=, boolean)=0 and %sysevalf(%superq(jsonfref)=, boolean)=0 %then %do;
5049
%put ERR%str(OR): [&sysmacroname] Specify either jsonpath or jsonfref, but not both.;
5150
%goto exit_macro;
@@ -54,38 +53,53 @@
5453
%* Check for non-existing jsonpath;
5554
%if %sysevalf(%superq(jsonpath)=, boolean)=0 %then %do;
5655
%if not %sysfunc(fileexist(&jsonpath)) %then %do;
57-
%put ERR%str(OR): [&sysmacroname] JSON file jsonpath=&jsonpath does not exist.;
56+
%put ERR%str(OR): [&sysmacroname] JSON file &=jsonpath does not exist.;
57+
%goto exit_macro;
58+
%end;
59+
%end;
60+
61+
%* Check for non-assigned jsonfref;
62+
%if %sysevalf(%superq(jsonfref)=, boolean)=0 %then %do;
63+
%if %sysfunc(fileref(&jsonfref)) gt 0 %then %do;
64+
%put ERR%str(OR): [&sysmacroname] JSON file reference &=jsonfref is not assigned.;
65+
%put %sysfunc(sysmsg());
66+
%goto exit_macro;
67+
%end;
68+
%if %sysfunc(fileref(&jsonfref)) lt 0 %then %do;
69+
%put ERR%str(OR): [&sysmacroname] JSON file referenced by &=jsonfref (%sysfunc(pathname(&jsonfref))) does not exist.;
5870
%goto exit_macro;
5971
%end;
6072
%end;
6173

6274
%* Check if datalib has been assigned ;
6375
%if %sysevalf(%superq(datalib)=, boolean)=0 %then %do;
6476
%if (%sysfunc(libref(&datalib)) ne 0 ) %then %do;
65-
%put ERR%str(OR): [&sysmacroname] datalib library &datalib has not been assigned.;
77+
%put ERR%str(OR): [&sysmacroname] datalib library &=datalib has not been assigned.;
78+
%put %sysfunc(sysmsg());
6679
%goto exit_macro;
6780
%end;
6881
%end;
6982

7083
%* Check if metadatalib has been assigned ;
7184
%if %sysevalf(%superq(metadatalib)=, boolean)=0 %then %do;
7285
%if (%sysfunc(libref(&metadatalib)) ne 0 ) %then %do;
73-
%put ERR%str(OR): [&sysmacroname] metadatalib library &metadatalib has not been assigned.;
86+
%put ERR%str(OR): [&sysmacroname] metadatalib library &=metadatalib has not been assigned.;
87+
%put %sysfunc(sysmsg());
7488
%goto exit_macro;
7589
%end;
7690
%end;
7791

7892
%* Rule: dropseqvar has to be Y or N *;
7993
%if "%substr(%upcase(&dropseqvar),1,1)" ne "Y" and "%substr(%upcase(&dropseqvar),1,1)" ne "N" %then
8094
%do;
81-
%put ERR%str(OR): [&sysmacroname] Required macro parameter dropseqvar=&dropseqvar must be Y or N.;
95+
%put ERR%str(OR): [&sysmacroname] Required macro parameter &=dropseqvar must be Y or N.;
8296
%goto exit_macro;
8397
%end;
8498

8599
%* Rule: savemetadata has to be Y or N *;
86100
%if "%substr(%upcase(&savemetadata),1,1)" ne "Y" and "%substr(%upcase(&savemetadata),1,1)" ne "N" %then
87101
%do;
88-
%put ERR%str(OR): [&sysmacroname] Required macro parameter savemetadata=&savemetadata must be Y or N.;
102+
%put ERR%str(OR): [&sysmacroname] Required macro parameter &=savemetadata must be Y or N.;
89103
%goto exit_macro;
90104
%end;
91105

macros/write_datasetjson.sas

+16-7
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,36 @@
6969

7070
%* Check for non-existing dataset ;
7171
%if not %sysfunc(exist(&dataset)) %then %do;
72-
%put ERR%str(OR): [&sysmacroname] Dataset dataset=&dataset does not exist.;
72+
%put ERR%str(OR): [&sysmacroname] Dataset &=dataset does not exist.;
7373
%goto exit_macro;
7474
%end;
7575

76-
%* Spoecify either jsonpath or jsonfref;
76+
%* Specify either jsonpath or jsonfref;
7777
%if %sysevalf(%superq(jsonpath)=, boolean) and %sysevalf(%superq(jsonfref)=, boolean) %then %do;
7878
%put ERR%str(OR): [&sysmacroname] Both jsonpath and jsonfref are missing. Specify one of them.;
7979
%goto exit_macro;
8080
%end;
8181

8282

83-
%* Spoecify either jsonpath or jsonfref;
83+
%* Specify either jsonpath or jsonfref;
8484
%if %sysevalf(%superq(jsonpath)=, boolean)=0 and %sysevalf(%superq(jsonfref)=, boolean)=0 %then %do;
8585
%put ERR%str(OR): [&sysmacroname] Specify either jsonpath or jsonfref, but not both.;
8686
%goto exit_macro;
8787
%end;
8888

89+
%* Check for non-assigned jsonfref;
90+
%if %sysevalf(%superq(jsonfref)=, boolean)=0 %then %do;
91+
%if %sysfunc(fileref(&jsonfref)) gt 0 %then %do;
92+
%put ERR%str(OR): [&sysmacroname] JSON file reference &=jsonfref is not assigned.;
93+
%put %sysfunc(sysmsg());
94+
%goto exit_macro;
95+
%end;
96+
%end;
8997

9098
%* Rule: usemetadata has to be Y or N *;
9199
%if "%substr(%upcase(&usemetadata),1,1)" ne "Y" and "%substr(%upcase(&usemetadata),1,1)" ne "N" %then
92100
%do;
93-
%put ERR%str(OR): [&sysmacroname] Required macro parameter usemetadata=&usemetadata must be Y or N.;
101+
%put ERR%str(OR): [&sysmacroname] Required macro parameter &=usemetadata must be Y or N.;
94102
%goto exit_macro;
95103
%end;
96104

@@ -103,7 +111,8 @@
103111

104112
%if %sysevalf(%superq(metadatalib)=, boolean)=0 %then %do;
105113
%if (%sysfunc(libref(&metadatalib)) ne 0 ) %then %do;
106-
%put ERR%str(OR): [&sysmacroname] metadatalib library &metadatalib has not been assigned.;
114+
%put ERR%str(OR): [&sysmacroname] metadatalib library &=metadatalib has not been assigned.;
115+
%put %sysfunc(sysmsg());
107116
%goto exit_macro;
108117
%end;
109118
%end;
@@ -127,13 +136,13 @@
127136
%* Rule: when usemetadata eq Y then decimalVariables will not be used *;
128137
%if "%substr(%upcase(&usemetadata),1,1)" eq "Y" %then %do;
129138
%if %sysevalf(%superq(decimalVariables)=, boolean)=0
130-
%then %put WAR%str(NING): [&sysmacroname] When macro parameter usemetadata=&usemetadata then parameter decimalVariables will not be used.;
139+
%then %put WAR%str(NING): [&sysmacroname] When macro parameter &=usemetadata then parameter decimalVariables will not be used.;
131140
%end;
132141

133142
%* Rule: allowed versions *;
134143
%if %substr(&datasetJSONVersion,1,3) ne %str(1.1) %then
135144
%do;
136-
%put ERR%str(OR): [&sysmacroname] Macro parameter datasetJSONVersion=&datasetJSONVersion. Allowed values: 1.1.x.;
145+
%put ERR%str(OR): [&sysmacroname] Macro parameter &=datasetJSONVersion. Allowed values: 1.1.x.;
137146
%goto exit_macro;
138147
%end;
139148

test/sashelp_class.sas

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ run;
4343
jsonpath=&project_folder\test\class.json,
4444
usemetadata=N,
4545
decimalVariables=bmi,
46-
iso8601Variables=birthdate,
4746
pretty=PRETTY);
4847

4948
proc datasets library=work noprint nolist nodetails;

0 commit comments

Comments
 (0)