Hi: The explantion of how to write a custom TAGSET template for use with the SAS XML Libname Engine is too long a discussion to go into here -- you really have to read the documentation and search for user group papers on the topic. Consider the attached screenshot of the output produced by the program below. As you can see, it shows an extra set of tags around OBSNO, NAME and SEX variables from SASHELP.CLASS. Then is shows another extra set of tags around AGE, HEIGHT and WEIGHT. I have structured my data quite rigidly -- this way, I know that OBSNO comes first, followed by NAME, then SEX, then AGE, HEIGHT and WEIGHT. So after the XML Libname engine writes the row delimiter tag, but before it writes the OBSNO info, I want it to write the opening CUST_INFO tag. So I made an event to write that tag. If OBSNO is not the first variable, then the tag will be written in the wrong place. Then, my template writes the other variables, but AFTER the SEX variable, the ending CUST_INFO tag is written. Then, BEFORE AGE, the DEMOGRAPHICS tag is written and AFTER WEIGHT, the DEMOGRAPHICS ending tag is written. Based on what you said, this PROC TEMPLATE method is ONE way to do what you want, assuming that all you are doing is adding extra tags at specific places around specific variables. I actually don't recommend the TAGSET template approach anymore. Learning the template language is quite a task and really, it is only a different mechanism for PUT statements. So, according to your customer's rules, the template method is probably not going to be acceptable either. It probably is better to work with a schema and the XML Mapper. Probably, if you have a schema (and you should have a schema for an unusual format such as you showed), you really need to try the XML Mapper approach. You'd have to get help from Tech Support for this approach (and honestly, you will probably need their help for the template approach too). Cynthia ods path work.temps(update) sasuser.templat(update) sashelp.tmplmst(read); proc template; define tagset Tagsets.extra_tags; notes "SAS-XML generic XML-Data"; define event SASTable; start: put "<ROOT_TAG>" NL; ndent; break; finish: xdent; put "</ROOT_TAG>" NL; break; end; define event SASRow; start: put "<"; put NAME; put ">"; put NL; ndent; break; finish: xdent; put "</"; put NAME; put ">"; put NL; break; end; define event ci_tag; start: put '<cust_info>' CR ; break; finish: put "</cust_info>" NL; break; end; define event dm_tag; start: put '<demographics>' CR ; break; finish: put "</demographics>" NL; break; end; define event SASColumn; start: trigger ci_tag start/ if cmp(upcase(NAME),'OBSNO'); trigger dm_tag start/ if cmp(upcase(NAME),'AGE'); ndent; put "<"; put TEXT / if cmp( XMLDATAFORM , "ATTRIBUTE" ); put " name=""" / if cmp( XMLDATAFORM , "ATTRIBUTE" ); put NAME; put """" / if cmp( XMLDATAFORM , "ATTRIBUTE" ); break; finish: xdent / if exist( MISSING ); break / if exist( MISSING ); put " />" / if cmp( XMLDATAFORM , "ATTRIBUTE" ); put NL / if cmp( XMLDATAFORM , "ATTRIBUTE" ); xdent / if cmp( XMLDATAFORM , "ATTRIBUTE" ); break / if cmp( XMLDATAFORM , "ATTRIBUTE" ); put "</"; put NAME; put ">"; put NL; xdent; trigger ci_tag finish / if cmp(upcase(NAME),'SEX'); trigger dm_tag finish / if cmp(upcase(NAME),'WEIGHT'); break; end; parent = tagsets.sasioXML; end; run; libname change xml 'c:\temp\Extra_Tags.txt' tagset=tagsets.extra_tags; data change.customer_data; ** need to ensure that variables are in a certain order; ** use length statement; ** always write out <cust_info> before the OBSNO variable; ** always write </cust_info> AFTER the SEX variable; ** always write out the <demographics> tag before the AGE variable; ** always write out the </demographics> tag AFTER the WEIGHT variable; length obsno 8 name $10 sex $1 age height weight 8; length ObsNo 8; set sashelp.class; ObsNo = _n_; if _n_ le 3 then output; run; libname change clear;
... View more