<?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: How to get all the list of all files as a dataset from particular folder? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531461#M145460</link>
    <description>&lt;P&gt;Hi ganeshk&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use this macro. The informats ddmmyy10. and commax18. work on a danish windows installation and should be changed to read whatever t&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dirlist(dsout,folder,sub=0);
	%if &amp;amp;sub = 1 %then %let recursive = /s;
	%else %let recursive =;

	filename tmp pipe "dir ""&amp;amp;folder"" &amp;amp;recursive /A-D /t:w";

	data &amp;amp;dsout (drop=rec upddato updtime);  	
		length folder file $255 extension $30 updated bytes 8;
		retain folder;
		format updated datetime.;
		infile tmp truncover end=eof;
		input rec $char300.;
		if substr(rec,1,13) = ' Directory of' then folder = substr(rec,15);
		else if substr(rec,1,1) ne '' then do;
			file = substr(rec,37);
			upddato = input(scan(rec,1,' '),ddmmyy10.);
			updtime = input(scan(rec,2,' '),time5.);
			updated = dhms(upddato,hour(updtime),minute(updtime),0);
			bytes =  input(scan(rec,3,' '),commax18.0);
			extension = scan(trim(file),-1,'.');
			output;
		end;
	run;
	filename tmp clear;
%mend;
%dirlist(temp,C:\Users\erlu\AppData\Roaming\SAS,sub=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;he windows DIR command returns in your environment. Use parm. sub=1 if you want to traverse subdirectories as well.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jan 2019 18:30:15 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-01-30T18:30:15Z</dc:date>
    <item>
      <title>How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531437#M145444</link>
      <description>&lt;P&gt;&lt;U&gt;Hi Team,&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create dataset with list of all files names present in that data set and there format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ex: In my D-Drive under the folder called "Analytics" i have these files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Path: "D:\Analytics"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" class="xl63" style="height: 14.4pt; width: 48pt;"&gt;&lt;STRONG&gt;Files&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;Type&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl64" style="height: 14.4pt; border-top: none;"&gt;File1&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;.csv&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl64" style="height: 14.4pt; border-top: none;"&gt;File2&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;.sas&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl64" style="height: 14.4pt; border-top: none;"&gt;File3&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;.xls&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl64" style="height: 14.4pt; border-top: none;"&gt;File4&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;.sas&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl64" style="height: 14.4pt; border-top: none;"&gt;File5&lt;/TD&gt;
&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;.csv&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to create all the listed files with there format as a single data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Ganesh K&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 17:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531437#M145444</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2019-01-30T17:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531461#M145460</link>
      <description>&lt;P&gt;Hi ganeshk&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use this macro. The informats ddmmyy10. and commax18. work on a danish windows installation and should be changed to read whatever t&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dirlist(dsout,folder,sub=0);
	%if &amp;amp;sub = 1 %then %let recursive = /s;
	%else %let recursive =;

	filename tmp pipe "dir ""&amp;amp;folder"" &amp;amp;recursive /A-D /t:w";

	data &amp;amp;dsout (drop=rec upddato updtime);  	
		length folder file $255 extension $30 updated bytes 8;
		retain folder;
		format updated datetime.;
		infile tmp truncover end=eof;
		input rec $char300.;
		if substr(rec,1,13) = ' Directory of' then folder = substr(rec,15);
		else if substr(rec,1,1) ne '' then do;
			file = substr(rec,37);
			upddato = input(scan(rec,1,' '),ddmmyy10.);
			updtime = input(scan(rec,2,' '),time5.);
			updated = dhms(upddato,hour(updtime),minute(updtime),0);
			bytes =  input(scan(rec,3,' '),commax18.0);
			extension = scan(trim(file),-1,'.');
			output;
		end;
	run;
	filename tmp clear;
%mend;
%dirlist(temp,C:\Users\erlu\AppData\Roaming\SAS,sub=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;he windows DIR command returns in your environment. Use parm. sub=1 if you want to traverse subdirectories as well.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 18:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531461#M145460</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-01-30T18:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531462#M145461</link>
      <description>&lt;P&gt;Here's a simple example, that will print a list of files to the log, and creates the dataset test&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename myDir "&amp;lt;your directory&amp;gt;" ;

data test (keep=filename);
	did=dopen("myDir") ;
	filecount=dnum(did) ;
	do i=1 to filecount ;
		filename=dread(did,i) ;
		put filename= ;
		output ;
	end ;
	rc=dclose(did) ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jan 2019 18:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531462#M145461</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-01-30T18:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531614#M145535</link>
      <description>&lt;P&gt;Hi Amsas,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Almost we got the output, Below is the screen shot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 121px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26722iEE4A5A21988AC603/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But i want format to be listed separate column. And if the there is no format,in this case ex: Input then these are folder, which need to be mention as folder in format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ganesh K&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 12:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531614#M145535</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2019-01-31T12:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531617#M145537</link>
      <description>&lt;P&gt;Hi Jensen,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't get proper output, below is the output which i got.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 564px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26723iDF9267E38B22680E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ganesh K&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 12:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531617#M145537</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2019-01-31T12:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531619#M145539</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;,&amp;nbsp;Please suggest on this&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 12:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531619#M145539</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2019-01-31T12:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531620#M145540</link>
      <description>&lt;P&gt;Actually it is OS command task.&lt;/P&gt;
&lt;P&gt;I would issue the command like 'dir /s /b d:\analysis\*.*&amp;nbsp; &amp;gt; c:\temp\list.log ' ,&lt;/P&gt;
&lt;P&gt;that command would save the resule into file list.log . And I will read list.log with SAS to get what you need.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 12:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531620#M145540</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-31T12:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531626#M145544</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17945"&gt;@Ganeshk&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What Ksharp suggests, is is principle what my macro is doing, except for an explitit named file,&amp;nbsp; so changing from pipe filename to a text file would make no difference. The SAS data step gets the same input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro takes the following format without problems:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dircmd.gif" style="width: 531px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26724iB857DCC3A80324EA/image-size/large?v=v2&amp;amp;px=999" role="button" title="dircmd.gif" alt="dircmd.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess your directory output is different somehow, as you do not get any content in the folder column. Try to write to the log what the DIR command returns, and copy that part of the log and post it to me. Add a put statement after the input statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		input rec $char300.;
		put rec;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 13:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531626#M145544</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-01-31T13:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531792#M145633</link>
      <description>&lt;P&gt;Sorry, I assumed you would be able to manipulate the output to get what you needed.&amp;nbsp;&lt;BR /&gt;Here's a version with the code to extract the extension&amp;nbsp;and filename - I'll leave you to figure out how to handle files without an extension&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test (keep=filename file ext);
	did=dopen("myDir") ;
	filecount=dnum(did) ;
	do i=1 to filecount ;
		filename=dread(did,i) ;
		put filename= ;
		ext=trim(scan(filename,-1,".","r")) ;
		lext=length(ext) ;
		lfil=length(filename) ;
		put _all_ ;
		file=substr(filename,1,lfil-lext-1) ;
		output ;

	end ;
	rc=dclose(did) ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 20:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/531792#M145633</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2019-01-31T20:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get all the list of all files as a dataset from particular folder?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/700611#M214423</link>
      <description>Thanks, AMSAS! Exactly what I was trying to accomplish.</description>
      <pubDate>Fri, 20 Nov 2020 21:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-all-the-list-of-all-files-as-a-dataset-from/m-p/700611#M214423</guid>
      <dc:creator>cannona3</dc:creator>
      <dc:date>2020-11-20T21:07:14Z</dc:date>
    </item>
  </channel>
</rss>

