Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
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 tree= The metadata folder uri, or the metadata path, in which to
21 create the document. This must exist.
22 @param name= Document object name. Avoid spaces.
23
24 @param desc= Document description (optional)
25 @param textrole= TextRole property (optional)
26 @param frefin= fileref to use (enables change if there is a conflict)
27 @param frefout= fileref to use (enables change if there is a conflict)
28 @param 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%mf_verifymacvars(tree name)
51
52/**
53 * check tree exists
54 */
55
56data _null_;
57 length type uri $256;
58 rc=metadata_pathobj("","&tree","Folder",type,uri);
59 call symputx('type',type,'l');
60 call symputx('treeuri',uri,'l');
61run;
62
63%mp_abort(
64 iftrue= (&type ne Tree)
65 ,mac=mm_createdocument.sas
66 ,msg=Tree &tree does not exist!
67)
68
69/**
70 * Check object does not exist already
71 */
72data _null_;
73 length type uri $256;
74 rc=metadata_pathobj("","&tree/&name","Note",type,uri);
75 call symputx('type',type,'l');
76 call symputx('docuri',uri,'l');
77 putlog (_all_)(=);
78run;
79
80%if &type = Document %then %do;
81 %put Document &name already exists in &tree!;
82 %return;
83%end;
84
85/**
86 * Now we can create the document
87 */
88filename &frefin temp;
89
90/* write header XML */
91data _null_;
92 file &frefin;
93 name=quote("&name");
94 desc=quote("&desc");
95 textrole=quote("&textrole");
96 treeuri=quote("&treeuri");
97
98 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid>"/
99 '<Metadata><Document IsHidden="0" PublicType="Note" UsageVersion="1000000"'/
100 " Name=" name " desc=" desc " TextRole=" textrole ">"/
101 "<Notes> "/
102 ' <TextStore IsHidden="0" Name=' name ' UsageVersion="0" '/
103 ' TextRole="SourceCode" StoredText="hello world" />' /
104 '</Notes>'/
105 /*URI="Document for public note" */
106 "<Trees><Tree ObjRef=" treeuri "/></Trees>"/
107 "</Document></Metadata><NS>SAS</NS>"/
108 "<Flags>268435456</Flags></AddMetadata>";
109run;
110
111filename &frefout temp;
112
113proc metadata in= &frefin out=&frefout verbose;
114run;
115
116%if &mdebug=1 %then %do;
117 /* write the response to the log for debugging */
118 data _null_;
119 infile &frefout lrecl=1048576;
120 input;
121 put _infile_;
122 run;
123%end;
124
125%mend mm_createdocument;