<?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: Create data set with names of data sets include name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614655#M179747</link>
    <description>&lt;P&gt;Try EQT operator.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=work._all_  noprint out=content 
(keep= memname where=( upcase(memname) eqt 'OFFERS'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 01 Jan 2020 10:39:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-01-01T10:39:05Z</dc:date>
    <item>
      <title>Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614639#M179735</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;There are 7&amp;nbsp; data sets in work library called :&lt;/P&gt;
&lt;P&gt;OFFERS190815&lt;/P&gt;
&lt;P&gt;OFFERS190820&lt;/P&gt;
&lt;P&gt;OFFERS190825&lt;/P&gt;
&lt;P&gt;OFFERS190902&lt;/P&gt;
&lt;P&gt;OFFERS190905&lt;/P&gt;
&lt;P&gt;OFFERS190910&lt;/P&gt;
&lt;P&gt;OFFERS190915&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I run this code in order to get list of datasets that start with "OFFERS" .&lt;/P&gt;
&lt;P&gt;I don't know why but&amp;nbsp; the output dataset called "CONTENT" has 70 rows and not 7.&lt;/P&gt;
&lt;P&gt;(Each data set name appears 10 times and I have 7 data sets so there are 70 rows)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=work._all_  noprint out=content 
(keep= memname where=(substr(upcase(memname),1,6) = 'OFFERS'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jan 2020 07:03:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614639#M179735</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-01T07:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614641#M179737</link>
      <description>&lt;P&gt;How many variable names are in each dataset? 10? Try keeping “name” as well to inspect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’d use DICTIONARY.TABLES for this using proc sql.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 07:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614641#M179737</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-01T07:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614655#M179747</link>
      <description>&lt;P&gt;Try EQT operator.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=work._all_  noprint out=content 
(keep= memname where=( upcase(memname) eqt 'OFFERS'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jan 2020 10:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614655#M179747</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-01T10:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614657#M179749</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp; &amp;nbsp;When you use PROC CONTENTS _all_ , the OUT= would account for all descriptor portion in the dataset. What this means is, suppose you have 7 variables in each of your dataset, the metadata is stored like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATASET1&amp;nbsp; &amp;nbsp;VAR1&lt;/P&gt;
&lt;P&gt;DATASET1&amp;nbsp; &amp;nbsp;VAR2&lt;/P&gt;
&lt;P&gt;DATASET1&amp;nbsp; &amp;nbsp;VAR3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And so on. Therefore the dataset name happens to have a duplicate record in order to account for each entry of a variable name. Hence, your&amp;nbsp;&lt;STRONG&gt;where=(substr(upcase(name),1,6) = 'OFFERS'))&amp;nbsp;&lt;/STRONG&gt;would still result in Duplicates corrresponding to the number of variables the dataset contains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So ideally you should be using DICTIONARY. TABLES or its view SASHELP.VTABLE. Albeit, you could still make PROC CONTENTS to work by resortiing to ODS OUTPUT objects that basically writes the printed message to an output dataset.&lt;/P&gt;
&lt;P&gt;Example,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ODS OUTPUT members=content(keep= name where=(substr(upcase(name),1,6) = 'OFFERS')); ;
proc contents data=work._all_   nods   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 11:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614657#M179749</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-01T11:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614658#M179750</link>
      <description>&lt;P&gt;Yes!! There are 10 varaibles in each data set .&lt;/P&gt;
&lt;P&gt;I just want to get a list of the data sets start with name "OFFER".&lt;/P&gt;
&lt;P&gt;What is the problem that I get #datasets X #varaibles in the&amp;nbsp; output data set?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 12:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614658#M179750</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-01T12:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614681#M179757</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Using proc CONTENTS is tantamount to reading DICTIONARY.COLUMNS - that is, it gets the metadata for both the tables and the variables - so you get a row for each variable for each table whose name passes the filter. Since you only need to get the distinct table names (i.e. metadata at the member level), CONTENTS is a wrong tool - you need to access DICTIONARY.TABLES instead, and it can be done directly only using SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                                                                                                              
  create table content as select memname from dictionary.tables where upcase (memname) eqt "OFFERS" ;                                   
quit ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Indirectly, you can also access the SASHELP.VTABLE, which can also be used as input in the DATA step and procedures other than SQL, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data content ;                                                                                                                          
  set sashelp.vtable ;                                                                                                                  
  where upcase (memname) =: "OFFERS" ;                                                                                                  
run ; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I wouldn't recommend it, as accessing DICTIONARY.TABLES is cleaner, faster, and doesn't pollute the log with extraneous info.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 18:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614681#M179757</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2020-01-01T18:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create data set with names of data sets include name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614690#M179759</link>
      <description>&lt;P&gt;The output of PROC CONTENTS is one observation per VARIABLE. Just add another step to eliminate the replicated member names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=content nodupkey;
  by memname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jan 2020 21:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-data-set-with-names-of-data-sets-include-name/m-p/614690#M179759</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-01T21:06:37Z</dc:date>
    </item>
  </channel>
</rss>

