<?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: Export Variable names from numerous different library locations in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344102#M22781</link>
    <description>&lt;P&gt;ODS Tagsets.ExcelXP is another option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro is another option for the export stage.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL EXECUTE with proc export is a better idea.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example but instead of creating a dataset change the code to export.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/4bfb7574713bedf4e011" target="_blank"&gt;https://gist.github.com/statgeek/4bfb7574713bedf4e011&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Mar 2017 15:31:39 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-03-24T15:31:39Z</dc:date>
    <item>
      <title>Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344074#M22776</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps someone could provide some input into the following, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the moment this is my sample code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Sample code for extracting variable information into an excel sheet*/
/*1 - Read in dataset(s)*/
libname x1 "location1";
libname x2 "location2";
libname x2 "location3";
/*2 - Create dataset(s) with variable info*/
proc contents data=x1._all_
out=contentslisting1;
run;
proc contents data=x1._all_
out=contentslisting1;
run;
/*3- Export data to excel*/
PROC EXPORT DATA=contentslisting1 outfile="location\location\location" dbms=xlsx; 
sheet="2009";
run;
PROC EXPORT DATA=contentslisting2 outfile="location\location\location" dbms=xlsx; 
sheet="2010";
run;
PROC EXPORT DATA=contentslisting3 outfile="location\location\location" dbms=xlsx; 
sheet="2011";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In some cases I might have to export data for 20 years so would have to do each step 20 times. Is there a way to quicken this process even more?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 14:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344074#M22776</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-03-24T14:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344077#M22777</link>
      <description>&lt;P&gt;If you're on SAS 9.4 use SASHELP.VTABLE or VCOLUMN to pull the variables of interest + ODS Excel to split into a single Excel workbook.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ODS EXCEL is only available in SAS 9.4+&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, blog post from yesterday &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sastraining/2017/03/23/exploring-the-content-of-the-dictionaries-table-and-vsview-sashelp-view/" target="_blank"&gt;http://blogs.sas.com/content/sastraining/2017/03/23/exploring-the-content-of-the-dictionaries-table-and-vsview-sashelp-view/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 14:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344077#M22777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-24T14:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344087#M22778</link>
      <description>&lt;P&gt;Hi, unforunately I do not have SAS 9.4. Is it possible to provide a macro soloution?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 14:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344087#M22778</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-03-24T14:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344101#M22780</link>
      <description>&lt;P&gt;Instead of macro please look at this:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table alldata as
   select *
   from dictionary.columns
   where libname in ('X1','X2','X3')
   order by libname, memname
   ;  
quit;


ods tagsets.excelxp file="path\file.xml"
 style=minimal  options(sheet_interval="Bygroup");

 proc print data=alldata noobs label;
   by libname;
 run;
ods tagsets.excelxp close;
&lt;/PRE&gt;
&lt;P&gt;This creates an XML file that Excel can read. If you truly need an XLSX file when done the do a file save as.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sheet names will have the library name on the tab so a more descriptive name for the libraries than X1 and X2 would be a good idea.&lt;/P&gt;
&lt;P&gt;Note that tagsets.excelxp will report on its own help documentation with this code:&lt;/P&gt;
&lt;P&gt;ods tagsets.excelxp options(doc='Quick');&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;ods tagsets.excelxp options(doc='Help');&lt;/P&gt;
&lt;P&gt;for the longer version.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 15:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344101#M22780</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-24T15:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344102#M22781</link>
      <description>&lt;P&gt;ODS Tagsets.ExcelXP is another option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro is another option for the export stage.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL EXECUTE with proc export is a better idea.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example but instead of creating a dataset change the code to export.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/4bfb7574713bedf4e011" target="_blank"&gt;https://gist.github.com/statgeek/4bfb7574713bedf4e011&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 15:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344102#M22781</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-24T15:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344116#M22782</link>
      <description>&lt;P&gt;Thanks for this, the code is extremley useful. I'm just wondering however, is it limited to a set number of libnames? For instance I'm actually calling from 27 different libraries but it only process up to 9 and stops then?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 16:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344116#M22782</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-03-24T16:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344125#M22785</link>
      <description>&lt;P&gt;I don't think there should be any limits in normal practice. If you have enough data sets and variables in them that the total number of rows exceeds what&amp;nbsp;a single sheet, or the number of sheets,&amp;nbsp;Excel can display then you would have had that problem with your original approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have many libraries to select from it may be simpler in the code to use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where LIBNAME not in ('SASHELP', 'SASUSER', 'WORK') (and any other libraries to exclude that may have currently defined that you do not want included)&lt;/P&gt;
&lt;P&gt;Note that the value of LIBNAME in the dataset created will be all capital letters so you need to use all caps in your syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 16:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344125#M22785</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-24T16:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Export Variable names from numerous different library locations</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344216#M22789</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Using meta data to create mutiple exce sheets in one workbook

inspired by
https://goo.gl/3ekrmk
https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344074

HAVE Meta data and three datasets (Inputs and outputs)
======================================================

Up to 40 obs WORK.META total obs=3

Obs    PTHINP     SHEET    TABLE

 1     d:/sd1/    2009      x1
 2     d:/sd2/    2010      x2
 3     d:/sd3/    2011      x3

Three SAS datasets

    d:/sd1/X1.sas7bdat
    d:/sd2/X2.sas.bdat
    d:/sd3/X3.sas7bdat

X1  Up to 40 obs from sd1.x1 total obs=3

Obs     NAME      SEX    HEIGHT    WEIGHT

 1     Alfred      M      69.0      112.5
 2     Alice       F      56.5       84.0
 3     Barbara     F      65.3       98.0

X2  Up to 40 obs from sd2.x2 total obs=3

Obs     NAME      SEX    AGE    HEIGHT

 1     Alfred      M      14     69.0
 2     Alice       F      13     56.5
 3     Barbara     F      13     65.3

X3  Up to 40 obs from sd3.x3 total obs=3

Obs     NAME      SEX    AGE    WEIGHT

 1     Alfred      M      14     112.5
 2     Alice       F      13      84.0
 3     Barbara     F      13      98.0



WANT (three worksheets 2009, 2010, 2011 in workbook d:/xls/sheets.xlsx)
=======================================================================

Workbook d:/xls/sheets.xlsx

2009 ( Variable names from dataset d/sd1/X1.sas7bdat)

  +------------+
  |     A      |
  -------------+
1 |  VARIABLE  |
  +------------+
2 |  NAME      |
3 |  SEX       |
4 |  HEIGHT    |
5 |  WEIGHT    |
  +------------+

[2009]


2010 ( Variable names from dataset d/sd1/X2.sas7bdat)

  +------------+
  |     A      |
  -------------+
1 |  VARIABLE  |
  +------------+
2 |  NAME      |
3 |  SEX       |
4 |  AGE       |
5 |  HEIGHT    |
  +------------+

[2010]


2011 ( Variable names from dataset d/sd1/X3.sas7bdat)

  +------------+
  |     A      |
  -------------+
1 |  VARIABLE  |
  +------------+
2 |  NAME      |
3 |  SEX       |
4 |  AGE       |
5 |  WEIGHT    |
  +------------+

[2011]

WORKING CODE
===========

       1 DOSUBL (load meta data)
       2 Datastep code to operate on meta data
       3 DOSUBL (create excel sheets

*                _                  _       _
 _ __ ___   __ _| | _____        __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| |   &amp;lt;  __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___|      \__,_|\__,_|\__\__,_|

;

libname sd1 "d:/sd1";
libname sd2 "d:/sd2";
libname sd3 "d:/sd3";

data sd1.x1(drop=age)
     sd2.x2(drop=weight)
     sd3.x3(drop=height);
  set sashelp.class(obs=3);
run;quit;

data meta;
 informat pthinp sheet $7. table $2.;
 input pthinp sheet table;
cards4;
d:/sd1/ 2009 x1
d:/sd2/ 2010 x2
d:/sd3/ 2011 x3
;;;;
run;quit;

*          _       _   _
 ___  ___ | |_   _| |_(_) ___  _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|

;

%utlfkil(d:/xls/sheets.xlsx);
libname xel "d:/xls/sheets.xlsx";

data _null_;
  if _n_=0 then do;
    %let rc=%sysfunc(dosubl('
      proc sql;
        select
            quote(trim(pthinp))
           ,quote(trim(sheet))
           ,quote(trim(table))
        into
           :inp separated by ","
          ,:she separated by ","
          ,:tbl separated by ","
        from
           meta
      ;quit;
    '));
  end;

  array inps[&amp;amp;sqlobs] $7  (&amp;amp;inp);
  array shes[&amp;amp;sqlobs] $4  (&amp;amp;she);
  array tbls[&amp;amp;sqlobs] $32 (&amp;amp;tbl);

  do i=1 to &amp;amp;sqlobs;

    call symputx('inpx',inps[i]);
    call symputx('shex',shes[i]);
    call symputx('tblx',tbls[i]);

    rc=dosubl('
      libname inp "&amp;amp;inpx.";
      proc transpose data=inp.&amp;amp;tblx.(obs=1)
          out=xel.f&amp;amp;shex.(rename=_name_=variable);
        var _all_;
      run;quit;
    ');

  end;
run;quit;

libname xel clear;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2017 22:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Export-Variable-names-from-numerous-different-library-locations/m-p/344216#M22789</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-24T22:48:21Z</dc:date>
    </item>
  </channel>
</rss>

