<?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: capture dataset name as a variable in a new dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24458#M4148</link>
    <description>Explore using the "pathname" function and consider that some characters are not acceptable in a SAS variable name.  So, you will likely already have a "libref" setup before your DATA step, so you will need to consider how to pre-process the info returned from the pathname function, either in a different DATA step or by using MACRO language and %SYSFUNC(pathname(&lt;YOURLIBREF&gt;))  to assign a macro variable.  Then this macro variable would be used later in your input processing DATA step to read the actual file and populate your variables.&lt;BR /&gt;
&lt;BR /&gt;
SAS 9.2 Language Dictionary: PATHNAME Function&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000245924.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000245924.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/YOURLIBREF&gt;</description>
    <pubDate>Tue, 28 Apr 2009 18:41:56 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-04-28T18:41:56Z</dc:date>
    <item>
      <title>capture dataset name as a variable in a new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24457#M4147</link>
      <description>I am building a dataset from several large date dependent datasets created by another user.  The dataset name has the date value in it.  I want to capture the datevalue from the users dataset name and add it to a new variable on my datset.  &lt;BR /&gt;
&lt;BR /&gt;
For example if dataset a contained the name testresults01/01/2009, I will take all the data elements from testresults01/01/2009 and add a variable which contains the value 01/01/2009.  &lt;BR /&gt;
&lt;BR /&gt;
Hope that makes sense.</description>
      <pubDate>Tue, 28 Apr 2009 17:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24457#M4147</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-28T17:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: capture dataset name as a variable in a new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24458#M4148</link>
      <description>Explore using the "pathname" function and consider that some characters are not acceptable in a SAS variable name.  So, you will likely already have a "libref" setup before your DATA step, so you will need to consider how to pre-process the info returned from the pathname function, either in a different DATA step or by using MACRO language and %SYSFUNC(pathname(&lt;YOURLIBREF&gt;))  to assign a macro variable.  Then this macro variable would be used later in your input processing DATA step to read the actual file and populate your variables.&lt;BR /&gt;
&lt;BR /&gt;
SAS 9.2 Language Dictionary: PATHNAME Function&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000245924.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000245924.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/YOURLIBREF&gt;</description>
      <pubDate>Tue, 28 Apr 2009 18:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24458#M4148</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-28T18:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: capture dataset name as a variable in a new dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24459#M4149</link>
      <description>Hello youngsh,&lt;BR /&gt;
&lt;BR /&gt;
Here is a little example on how to do it:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Let's simulate some data to illustrate the program:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
data T01_20091001&lt;BR /&gt;
     T01_20091002&lt;BR /&gt;
     T01_20091003;&lt;BR /&gt;
do i=1 to 10000;&lt;BR /&gt;
 x=ranuni(0);&lt;BR /&gt;
 select;&lt;BR /&gt;
 when(mod(i,3)=0) output T01_20091001;&lt;BR /&gt;
 when(mod(i,3)=1) output T01_20091002;&lt;BR /&gt;
 when(mod(i,3)=2) output T01_20091003;&lt;BR /&gt;
 otherwise put "Never seen !";&lt;BR /&gt;
 end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data T02_metadata;&lt;BR /&gt;
to_import="T01_20091001"; output;&lt;BR /&gt;
to_import="T01_20091002"; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;This macro will append the content of the file T01_&lt;I&gt;date&lt;/I&gt; to T04_union. The date is added to the input file before the append takes place. This is done with a "view" (this doesn't require disk space)&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
%macro import_file_with_date(date);&lt;BR /&gt;
 proc sql;&lt;BR /&gt;
  create view T03_temp as&lt;BR /&gt;
  select input("&amp;amp;date",yymmdd8.) format=date9. as date, *&lt;BR /&gt;
  from T01_&amp;amp;date;&lt;BR /&gt;
 quit;&lt;BR /&gt;
&lt;BR /&gt;
 proc append data=T03_temp out=T04_union;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
 proc sql;&lt;BR /&gt;
 drop view T03_temp;&lt;BR /&gt;
 quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Let us invoke the macro "manually"&lt;/B&gt;&lt;BR /&gt;
* import 1 file manually;&lt;BR /&gt;
%import_file_with_date(20091001);&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;You can generate macro calls using a data step&lt;/B&gt;&lt;BR /&gt;
* import multiple files from list in T02_metadata;&lt;BR /&gt;
data _NULL_;&lt;BR /&gt;
set T02_metadata;&lt;BR /&gt;
call execute(cats('%import_File_with_date(',scan(to_import,2,"_"),');'));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
You could add some code in the macro to handle re-loads.&lt;BR /&gt;
&lt;BR /&gt;
I hope this helps?&lt;BR /&gt;
&lt;BR /&gt;
yoba

Message was edited by: yoba</description>
      <pubDate>Tue, 28 Apr 2009 20:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/capture-dataset-name-as-a-variable-in-a-new-dataset/m-p/24459#M4149</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-28T20:52:07Z</dc:date>
    </item>
  </channel>
</rss>

