Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_createdocument.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Create a Document object in a metadata folder
4 @details Document objects are useful for storing properties in metadata.
5 This macro is idempotent - it will not create an object with the same name
6 in the same location, twice.
7 Note - the filerefs are left open, to enable inspection after running the
8 macro (or importing into an xmlmap if needed).
9
10 usage:
11
12 %mm_createdocument(tree=/User Folders/sasdemo
13 ,name=MyNote)
14
15 <h4> SAS Macros </h4>
16 @li mp_abort.sas
17 @li mf_verifymacvars.sas
18
19
20 @param [in] tree= The metadata folder uri, or the metadata path, in which to
21 create the document. This must exist.
22 @param [in] name= Document object name. Avoid spaces.
23
24 @param [in] desc= Document description (optional)
25 @param [in] textrole= TextRole property (optional)
26 @param [in] frefin= fileref to use (enables change if there is a conflict)
27 @param [out] frefout= fileref to use (enables change if there is a conflict)
28 @param [in] mDebug= set to 1 to show debug messages in the log
29
30 @author Allan Bowe
31
32**/
33
34%macro mm_createdocument(
35 tree=/User Folders/sasdemo
36 ,name=myNote
37 ,desc=Created by &sysmacroname
38 ,textrole=
39 ,frefin=mm_in
40 ,frefout=mm_out
41 ,mDebug=1
42 );
43
44%local mD;
45%if &mDebug=1 %then %let mD=;
46%else %let mD=%str(*);
47%&mD.put Executing &sysmacroname..sas;
48%&mD.put _local_;
49
50%mp_abort(iftrue= (%mf_verifymacvars(tree name)=0)
51 ,mac=&sysmacroname
52 ,msg=%str(Empty inputs: tree name)
53)
54
55/**
56 * check tree exists
57 */
58
59data _null_;
60 length type uri $256;
61 rc=metadata_pathobj("","&tree","Folder",type,uri);
62 call symputx('type',type,'l');
63 call symputx('treeuri',uri,'l');
64run;
65
66%mp_abort(
67 iftrue= (&type ne Tree)
68 ,mac=mm_createdocument.sas
69 ,msg=Tree &tree does not exist!
70)
71
72/**
73 * Check object does not exist already
74 */
75data _null_;
76 length type uri $256;
77 rc=metadata_pathobj("","&tree/&name","Note",type,uri);
78 call symputx('type',type,'l');
79 call symputx('docuri',uri,'l');
80 putlog (_all_)(=);
81run;
82
83%if &type = Document %then %do;
84 %put Document &name already exists in &tree!;
85 %return;
86%end;
87
88/**
89 * Now we can create the document
90 */
91filename &frefin temp;
92
93/* write header XML */
94data _null_;
95 file &frefin;
96 name=quote("&name");
97 desc=quote("&desc");
98 textrole=quote("&textrole");
99 treeuri=quote("&treeuri");
100
101 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid>"/
102 '<Metadata><Document IsHidden="0" PublicType="Note" UsageVersion="1000000"'/
103 " Name=" name " desc=" desc " TextRole=" textrole ">"/
104 "<Notes> "/
105 ' <TextStore IsHidden="0" Name=' name ' UsageVersion="0" '/
106 ' TextRole="SourceCode" StoredText="hello world" />' /
107 '</Notes>'/
108 /*URI="Document for public note" */
109 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
110 "</Document></Metadata><NS>SAS</NS>"/
111 "<Flags>268435456</Flags></AddMetadata>";
112run;
113
114filename &frefout temp;
115
116proc metadata in= &frefin out=&frefout verbose;
117run;
118
119%if &mdebug=1 %then %do;
120 /* write the response to the log for debugging */
121 data _null_;
122 infile &frefout lrecl=1048576;
123 input;
124 put _infile_;
125 run;
126%end;
127
128%mend mm_createdocument;