<?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: Multiple file saving from a directory in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73056#M15726</link>
    <description>You can use the %scan-function to extract the part before .txt, afterwards it may be necessary to remove any other char not allowed in dataset names. The translate function could be useful for that job.</description>
    <pubDate>Mon, 09 Feb 2009 09:01:52 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2009-02-09T09:01:52Z</dc:date>
    <item>
      <title>Multiple file saving from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73055#M15725</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
I am using a macro to open multiple txt files from a directory but want to store them under a subsetname of the files. Once i assign the file name it can't store it because of the txt extension, how can i make it to store my the files? Could somebody please help me figure out what is wrong here?&lt;BR /&gt;
&lt;BR /&gt;
This is the code;&lt;BR /&gt;
&lt;BR /&gt;
macro basic1;&lt;BR /&gt;
%let filrf=mydir;&lt;BR /&gt;
%let rc=%sysfunc(filename(filrf,"F:\RESEARCH MELISSA\Short USA DATA\")); /* assign dir name */&lt;BR /&gt;
%let did=%sysfunc(dopen(&amp;amp;filrf)); /* open directory */&lt;BR /&gt;
%let lstname=; /* clear filename macro var */&lt;BR /&gt;
%let memcount=%sysfunc(dnum(&amp;amp;did)); /* get # files in directory */&lt;BR /&gt;
%if &amp;amp;memcount &amp;gt; 0 %then /* check for blank directory */&lt;BR /&gt;
	%do i=1 %to &amp;amp;memcount; /* start loop for files */&lt;BR /&gt;
	%let lstname=%sysfunc(dread(&amp;amp;did,&amp;amp;i)); /* get file name to process */&lt;BR /&gt;
	%let lstname2=%sysfunc(substr("&amp;amp;lstname",24,7));&lt;BR /&gt;
	filename dr "F:\RESEARCH MELISSA\Short USA DATA\&amp;amp;lstname"; /* assign file name */&lt;BR /&gt;
	proc import out=&amp;amp;LSTNAME2&lt;BR /&gt;
	datafile=dr;&lt;BR /&gt;
	DBMS=TAB Replace;&lt;BR /&gt;
	getnames=yes;&lt;BR /&gt;
	datarow=2;&lt;BR /&gt;
	run;&lt;BR /&gt;
	%end;&lt;BR /&gt;
%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;
%mend basic1;

Message was edited by: mporras</description>
      <pubDate>Fri, 06 Feb 2009 12:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73055#M15725</guid>
      <dc:creator>mporras</dc:creator>
      <dc:date>2009-02-06T12:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple file saving from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73056#M15726</link>
      <description>You can use the %scan-function to extract the part before .txt, afterwards it may be necessary to remove any other char not allowed in dataset names. The translate function could be useful for that job.</description>
      <pubDate>Mon, 09 Feb 2009 09:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73056#M15726</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2009-02-09T09:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple file saving from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73057#M15727</link>
      <description>to test the validity of a string for use as a name (either data set name or variable name) use the function NVALID() &lt;BR /&gt;
For example, replace unsuitable name with a generated name like[pre]      %if not %sysfunc( nValid( &amp;amp;lstName2 )) %then %do ;&lt;BR /&gt;
         %let newName  = gen%SYSINDEX ;&lt;BR /&gt;
         %put lstname2 = %quote(&amp;amp;lstName2) unsuitable. Using  &amp;amp;newName ;&lt;BR /&gt;
         %let lstname2 = &amp;amp;newName ;&lt;BR /&gt;
      %end ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
There I used %sysindex. &amp;amp;SYSINDEX delivers a constant each time the macro in which it is present is called. However I want an increasing counter. So I create %SYSINDEX because it is not automatically available, and is very convenient and simple to create.[pre]%macro sysindex ;&lt;BR /&gt;
&amp;amp;sysindex &lt;BR /&gt;
%mend  sysindex ;[/pre]It provides a macro wrapper around &amp;amp;sysindex.&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Mon, 09 Feb 2009 09:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-file-saving-from-a-directory/m-p/73057#M15727</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-09T09:32:47Z</dc:date>
    </item>
  </channel>
</rss>

