<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Merge SAS metadata (formats and labels) to SQL Server tables and views in Administration and Deployment</title>
    <link>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488127#M13962</link>
    <description>&lt;P&gt;For SAS datasets, I would use proc datasets to get the attributes and restore them on the target:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let targlib=work;
%let targdata=demo;

data &amp;amp;targlib..&amp;amp;targdata;
set sashelp.demographics (obs=10);
format _all_;
attrib _all_ label="";
run;

title "Dataset stripped of attributes";

proc contents data=&amp;amp;targlib..&amp;amp;targdata;
run;

proc datasets library=sashelp nolist;
contents data=demographics out=work.myattr noprint;
quit;

data _null_;
set work.myattr end=eof;
if _n_ = 1 then call execute("
  proc datasets library=&amp;amp;targlib nolist;
  modify &amp;amp;targdata;
");
call execute('attrib ' !! trim(name));
if format &amp;gt; '' then call execute(" format=" !! trim(format) !! strip(put(formatl,best.)) !! '.' !! strip(put(formatd,best.)));
if label &amp;gt; '' then call execute(" label='" !! trim(label) !! "'");
call execute(";");
if eof then call execute('quit;');
run;

title "Dataset with attributes restored";

proc contents data=&amp;amp;targlib..&amp;amp;targdata;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With views, restoring the underlying datasets' attributes should fix it; if the view changes attributes on its own, the code needs to be changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea if this code would work through a SAS/ACCESS connection.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Aug 2018 08:55:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-08-20T08:55:48Z</dc:date>
    <item>
      <title>Merge SAS metadata (formats and labels) to SQL Server tables and views</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488091#M13958</link>
      <description>&lt;P&gt;I need to add SAS metadata (formats and labels) to&amp;nbsp;SQL Server tables and views such that&amp;nbsp;when downstream users access the table via the meta engine, the table has the formats and labels applied.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's some pseudocode:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mysaslib.demographics; set sashelp.demographics;run;
data mysaslib.demographics2;set sashelp.demographics;format _all_;attrib _all_ label="";run;

proc print data=mysaslib.demographics (obs=10) label;run;
proc print data=mysaslib.demographics2 (obs=10) label;run;

proc append data=mysaslib.demographics base=mySQLlib.demographics;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then define the mysqllib library in SMC, register the SQL Server table, and import metadata.&amp;nbsp; But of course it doesn't have the SAS metadata.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to "merge" the SAS metadata onto the table definition in the SQL Server library?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I have a few SQL Server views against that table, with different columns for each view.&amp;nbsp; I would like those views to also have the SAS metadata applied.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd prefer a programmatic approach, say via PROC METADATA, rather than a process to follow via the SMC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The end result is I would want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mysqllib.demographics (obs=10) label;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;to match the output from the 1st proc print above, rather than the 2nd output.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks...&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 02:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488091#M13958</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2018-08-20T02:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merge SAS metadata (formats and labels) to SQL Server tables and views</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488127#M13962</link>
      <description>&lt;P&gt;For SAS datasets, I would use proc datasets to get the attributes and restore them on the target:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let targlib=work;
%let targdata=demo;

data &amp;amp;targlib..&amp;amp;targdata;
set sashelp.demographics (obs=10);
format _all_;
attrib _all_ label="";
run;

title "Dataset stripped of attributes";

proc contents data=&amp;amp;targlib..&amp;amp;targdata;
run;

proc datasets library=sashelp nolist;
contents data=demographics out=work.myattr noprint;
quit;

data _null_;
set work.myattr end=eof;
if _n_ = 1 then call execute("
  proc datasets library=&amp;amp;targlib nolist;
  modify &amp;amp;targdata;
");
call execute('attrib ' !! trim(name));
if format &amp;gt; '' then call execute(" format=" !! trim(format) !! strip(put(formatl,best.)) !! '.' !! strip(put(formatd,best.)));
if label &amp;gt; '' then call execute(" label='" !! trim(label) !! "'");
call execute(";");
if eof then call execute('quit;');
run;

title "Dataset with attributes restored";

proc contents data=&amp;amp;targlib..&amp;amp;targdata;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With views, restoring the underlying datasets' attributes should fix it; if the view changes attributes on its own, the code needs to be changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea if this code would work through a SAS/ACCESS connection.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 08:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488127#M13962</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-20T08:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Merge SAS metadata (formats and labels) to SQL Server tables and views</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488135#M13965</link>
      <description>&lt;P&gt;Perhaps not a programmatic approach, but still...&lt;/P&gt;
&lt;P&gt;Create template tables in SAS with desired metadata, import them into the metadata server.&lt;/P&gt;
&lt;P&gt;Then again import columns definition from those template tables to the real SQL Server table definitions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your tables share many columns, you take a look at standardizing columns, can also reduce manual work a bit:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=etlug&amp;amp;docsetTarget=n0kw06lyyymqzin14dl0a1x9dtat.htm&amp;amp;docsetVersion=4.903&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=etlug&amp;amp;docsetTarget=n0kw06lyyymqzin14dl0a1x9dtat.htm&amp;amp;docsetVersion=4.903&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 10:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488135#M13965</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-08-20T10:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge SAS metadata (formats and labels) to SQL Server tables and views</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488386#M13972</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yeah that's the approach I've taken.&amp;nbsp; My code looks something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* create objects to assist with metadata creation in SMC ;
* main table ;
* build keep statement based on the table definition ;
proc contents data=pdc.PDC_IDENTIFIED_SCD2 (drop=CHECKSUM) out=contents (keep=name varnum) noprint;
run;
proc sql noprint;
   select name into :keep separated by " " from contents order by varnum;
   drop table contents;
quit;
%put &amp;amp;=keep;

data pdcdata.meta_PDC_IDENTIFIED_SCD2;
   * set column order ;
   if 0 then set pdc.PDC_IDENTIFIED_SCD2;
   * augment with the column attributes ;
   %include attrib;
   * extra columns not in the metadata workbook ;
   attrib
      PDC_IDENTIFIED_SCD2_ID length=8
      VALID_FROM             length=8  format=datetime21.
      VALID_TO               length=8  format=datetime21.
      CURRENT_RECORD         length=$1 
/*    CHECKSUM               length=$32   format=hex32. */
   ;   
   keep &amp;amp;keep;
   call missing(of _all_);
   stop;
run;
proc contents;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;PDC is a SQL Server library.&amp;nbsp; PDCDATA is a SAS library.&amp;nbsp; %include attrib is a huge (350+ variables) attributes block built from metadata in an Excel workbook (does anyone actually use Excel as a spreadsheet &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once these SAS datasets are created:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* Launch SMC&lt;/P&gt;&lt;P&gt;* Navigate to the SQL Server library&lt;/P&gt;&lt;P&gt;* Open the table object&lt;/P&gt;&lt;P&gt;* Delete the rows (I can't delete all rows, as some are referenced by indexes, etc)&lt;/P&gt;&lt;P&gt;* Click Import&lt;/P&gt;&lt;P&gt;* Navigate to the corresponding SAS meta_* table&lt;/P&gt;&lt;P&gt;* Import the columns&lt;/P&gt;&lt;P&gt;* Drag the columns into the desired order&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still, after 10+ years of SAS 9.x, it would have been nice if R&amp;amp;D had enhanced PROC METALIB to do this programmatically.&amp;nbsp; For example, use PROC CONTENTS against the SAS dataset, then a DATA= option to PROC METALIB which would programmatically merge the SAS metadata from PROC CONTENTS into the SQL Server table metadata.&amp;nbsp; Surely I'm not the only one that's had to do this over 10+ years?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, this approach breaks if you later select "Update Metadata" in SMC.&amp;nbsp; Plus it's obviously prone to error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, I'm not the one maintaining the metadata, a colleague is.&amp;nbsp; And lucky we only need to do this against 4 table objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because this is urgent, I also opened a SAS TS track.&amp;nbsp; I'll update this post if they suggest a better way.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 22:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488386#M13972</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2018-08-20T22:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Merge SAS metadata (formats and labels) to SQL Server tables and views</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488435#M13976</link>
      <description>PROC metalib might work, I just haven't invested the time to explore it.&lt;BR /&gt;Generally I agree with expectation you have on the SW.</description>
      <pubDate>Tue, 21 Aug 2018 06:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Merge-SAS-metadata-formats-and-labels-to-SQL-Server-tables-and/m-p/488435#M13976</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-08-21T06:14:53Z</dc:date>
    </item>
  </channel>
</rss>

