|
1 | 1 | %macro write_datasetjson(
|
2 | 2 | dataset=,
|
3 | 3 | jsonpath=,
|
| 4 | + jsonfref=, |
4 | 5 | usemetadata=N,
|
5 | 6 | metadatalib=,
|
6 | 7 | decimalVariables=,
|
7 |
| - iso8601Variables=, |
8 | 8 | datasetJSONVersion=1.1.0,
|
9 | 9 | fileOID=,
|
10 | 10 | originator=,
|
|
59 | 59 | %* Check for missing parameters ;
|
60 | 60 | %let _Missing=;
|
61 | 61 | %if %sysevalf(%superq(dataset)=, boolean) %then %let _Missing = &_Missing dataset;
|
62 |
| - %if %sysevalf(%superq(jsonpath)=, boolean) %then %let _Missing = &_Missing jsonpath; |
63 | 62 | %if %sysevalf(%superq(usemetadata)=, boolean) %then %let _Missing = &_Missing usemetadata;
|
64 | 63 |
|
65 | 64 | %if %length(&_Missing) gt 0
|
|
68 | 67 | %goto exit_macro;
|
69 | 68 | %end;
|
70 | 69 |
|
| 70 | + %* Check for non-existing dataset ; |
| 71 | + %if not %sysfunc(exist(&dataset)) %then %do; |
| 72 | + %put ERR%str(OR): [&sysmacroname] Dataset dataset=&dataset does not exist.; |
| 73 | + %goto exit_macro; |
| 74 | + %end; |
| 75 | + |
| 76 | + %* Spoecify either jsonpath or jsonfref; |
| 77 | + %if %sysevalf(%superq(jsonpath)=, boolean) and %sysevalf(%superq(jsonfref)=, boolean) %then %do; |
| 78 | + %put ERR%str(OR): [&sysmacroname] Both jsonpath and jsonfref are missing. Specify one of them.; |
| 79 | + %goto exit_macro; |
| 80 | + %end; |
| 81 | + |
| 82 | + |
| 83 | + %* Spoecify either jsonpath or jsonfref; |
| 84 | + %if %sysevalf(%superq(jsonpath)=, boolean)=0 and %sysevalf(%superq(jsonfref)=, boolean)=0 %then %do; |
| 85 | + %put ERR%str(OR): [&sysmacroname] Specify either jsonpath or jsonfref, but not both.; |
| 86 | + %goto exit_macro; |
| 87 | + %end; |
| 88 | + |
| 89 | + |
71 | 90 | %* Rule: usemetadata has to be Y or N *;
|
72 | 91 | %if "%substr(%upcase(&usemetadata),1,1)" ne "Y" and "%substr(%upcase(&usemetadata),1,1)" ne "N" %then
|
73 | 92 | %do;
|
|
92 | 111 | %* Rule: when usemetadata eq Y then metadata datasets need to exist in the metadatalib library *;
|
93 | 112 | %if "%substr(%upcase(&usemetadata),1,1)" eq "Y" %then %do;
|
94 | 113 | %if not %sysfunc(exist(&metadatalib..metadata_study)) %then %do;
|
95 |
| - %put ERR%str(OR): [&sysmacroname] When usemetadata=Y, then &metadatalib..metadata_study must exist.; |
| 114 | + %put ERR%str(OR): [&sysmacroname] usemetadata=Y, but &metadatalib..metadata_study does not exist.; |
96 | 115 | %goto exit_macro;
|
97 | 116 | %end;
|
98 | 117 | %if not %sysfunc(exist(&metadatalib..metadata_tables)) %then %do;
|
99 |
| - %put ERR%str(OR): [&sysmacroname] When usemetadata=Y, then &metadatalib..metadata_tables must exist.; |
| 118 | + %put ERR%str(OR): [&sysmacroname] usemetadata=Y, but &metadatalib..metadata_tables does not exist.; |
100 | 119 | %goto exit_macro;
|
101 | 120 | %end;
|
102 | 121 | %if not %sysfunc(exist(&metadatalib..metadata_columns)) %then %do;
|
103 |
| - %put ERR%str(OR): [&sysmacroname] When usemetadata=Y, then &metadatalib..metadata_columns must exist.; |
| 122 | + %put ERR%str(OR): [&sysmacroname] usemetadata=Y, but &metadatalib..metadata_columns does not exist.; |
104 | 123 | %goto exit_macro;
|
105 | 124 | %end;
|
106 | 125 | %end;
|
|
109 | 128 | %if "%substr(%upcase(&usemetadata),1,1)" eq "Y" %then %do;
|
110 | 129 | %if %sysevalf(%superq(decimalVariables)=, boolean)=0
|
111 | 130 | %then %put WAR%str(NING): [&sysmacroname] When macro parameter usemetadata=&usemetadata then parameter decimalVariables will not be used.;
|
112 |
| - %if %sysevalf(%superq(iso8601Variables)=, boolean)=0 |
113 |
| - %then %put WAR%str(NING): [&sysmacroname] When macro parameter usemetadata=&usemetadata then parameter iso8601Variables will not be used.; |
114 | 131 | %end;
|
115 | 132 |
|
116 | 133 | %* Rule: allowed versions *;
|
|
405 | 422 | where (datatype in ('datetime', 'date', 'time')) and (targetdatatype = 'integer');
|
406 | 423 | quit;
|
407 | 424 |
|
408 |
| - %if %sysevalf(%superq(iso8601Variables)=, boolean)=0 %then %do; |
409 |
| - data work.column_metadata; |
410 |
| - set work.column_metadata; |
411 |
| - %do _count=1 %to %sysfunc(countw(&iso8601Variables, %str(' '))); |
412 |
| - if upcase(name)=upcase("%scan(&iso8601Variables, &_count)") then do; |
413 |
| - if missing(displayFormat) then |
414 |
| - putlog "WAR" "NING: [&sysmacroname] &dataset.." name +(-1) ": variable has no format attached." name= dataType= targetDataType=; |
415 |
| - else do; |
416 |
| - putlog name= dataType= targetDataType= displayFormat=; |
417 |
| - end; |
418 |
| - end; |
419 |
| - %end; |
420 |
| - run; |
421 |
| - %let _iso8601_variables=&iso8601Variables; |
422 |
| - %end; |
423 |
| - |
424 | 425 | %if %sysevalf(%superq(_iso8601_variables)=, boolean)=0 %then %do;
|
425 | 426 | %put NOTE: [&sysmacroname] &dataset: numeric ISO 8601 variables converted to strings: &_iso8601_variables;
|
426 | 427 | %end;
|
|
486 | 487 | ;
|
487 | 488 | quit;
|
488 | 489 |
|
489 |
| - filename json&_random "&jsonpath"; |
| 490 | + %if %sysevalf(%superq(jsonpath)=, boolean)=0 %then |
| 491 | + filename json&_random "&jsonpath";; |
| 492 | + %if %sysevalf(%superq(jsonfref)=, boolean)=0 %then |
| 493 | + filename json&_random "%sysfunc(pathname(&jsonfref))";; |
490 | 494 |
|
491 | 495 | data work.column_metadata;
|
492 | 496 | retain itemOID name label dataType targetDataType length displayFormat keySequence;
|
|
0 commit comments