<?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: SAS: How to Look into folder/subfolder. Open and concatenate data files (if condition was satisf in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/358897#M274456</link>
    <description>&lt;P&gt;There's a macro in the macro appendix that will list all folders/subfolders etc for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This relatively long macro will do the same and store it in a dataset for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext);
	%local filrf rc did memcnt name i;
	%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
	%let did=%sysfunc(dopen(&amp;amp;filrf));

	%if &amp;amp;did eq 0 %then
		%do;
			%put Directory &amp;amp;dir cannot be open or does not exist;

			%return;
		%end;

	%do i = 1 %to %sysfunc(dnum(&amp;amp;did));
		%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

		%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then
			%do;
				%put &amp;amp;dir\&amp;amp;name;
				%let file_name =  %qscan(&amp;amp;name,1,.);
				%put &amp;amp;file_name;

				data _tmp;
					length dir $512 name $100;
					dir=symget("dir");
					name=symget("name");
					path = catx('\',dir,name);
					the_name = substr(name,1,find(name,'.')-1);
				run;

				proc append base=list data=_tmp force;
				run;

				quit;

				proc sql;
					drop table _tmp;
				quit;

			%end;
		%else %if %qscan(&amp;amp;name,2,.) = %then
			%do;
				%list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
			%end;
	%end;

	%let rc=%sysfunc(dclose(&amp;amp;did));
	%let rc=%sysfunc(filename(filrf));
%mend list_files;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;IMO this question is unreasonable&amp;nbsp;to expect an answer to all at once. You're better off trying it yourself and asking for help with specific portions. You seem to have the process mapped out so you should be able to find examples online or here for each section.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 May 2017 02:56:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-05-16T02:56:09Z</dc:date>
    <item>
      <title>SAS: How to Look into folder/subfolder. Open and concatenate data files (if condition was satisfied)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/358896#M274455</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind a new in dealing with files and folders in SAS. I'm hoping someone can help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG width="188" height="118" title="input_table.PNG" alt="input_table.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/8897iE165CEE8FFC79347/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Procedure:&lt;/P&gt;
&lt;P&gt;&lt;IMG width="500" height="363" title="folder_file_structure.PNG" alt="folder_file_structure.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/8898i77387A179663ED73/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Go to&lt;FONT color="#0000ff"&gt; MainFolder&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;2. Look for &lt;FONT color="#0000ff"&gt;subfolder (1st row:&amp;nbsp;Sub1)&lt;/FONT&gt; declared into the &lt;FONT color="#ff0000"&gt;Input_Table&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;3. Open&amp;nbsp;EACH subfolder from &lt;FONT color="#0000ff"&gt;Sub1_?&lt;/FONT&gt;&amp;nbsp;to &lt;FONT color="#0000ff"&gt;Sub1_1_?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;4. Open &lt;FONT color="#0000ff"&gt;*.xls&lt;/FONT&gt; file. see &lt;FONT color="#ff0000"&gt;*.xls &lt;/FONT&gt;sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Locate cell &lt;FONT color="#0000ff"&gt;C2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IF value of &lt;FONT color="#0000ff"&gt;C2&lt;/FONT&gt; is equal to &lt;FONT color="#0000ff"&gt;dataID (1st row: abc123 of&lt;/FONT&gt;&amp;nbsp;&lt;FONT color="#0000ff"&gt;Input_Table&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;5.&amp;nbsp;THEN OPEN &lt;FONT color="#0000ff"&gt;measure.csv. &lt;FONT color="#000000"&gt;see&lt;/FONT&gt; &lt;FONT color="#ff0000"&gt;measure.csv&lt;/FONT&gt; &lt;FONT color="#000000"&gt;sample&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;6. repeat 2-5 (next row of Input_table)&lt;/P&gt;
&lt;P&gt;7. concatenate &lt;FONT color="#0000ff"&gt;measure.csv&lt;/FONT&gt;, see &lt;FONT color="#ff0000"&gt;output table&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG width="273" height="117" title="xls_structure.PNG" alt="xls_structure.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/8900i3321C4A5606F2A13/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG width="312" height="117" title="measure_csv.PNG" alt="measure_csv.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/8901i248258F83511E12E/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG width="626" height="283" title="output_table.PNG" alt="output_table.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/8899i87224742843E9761/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im using SAS9.4m3 /&amp;nbsp;Windows 7.&lt;/P&gt;
&lt;P&gt;I hope i illustrate my query properly. Let me know if you have questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate if you can explain the codes as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 02:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/358896#M274455</guid>
      <dc:creator>Karem</dc:creator>
      <dc:date>2017-05-16T02:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: How to Look into folder/subfolder. Open and concatenate data files (if condition was satisf</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/358897#M274456</link>
      <description>&lt;P&gt;There's a macro in the macro appendix that will list all folders/subfolders etc for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This relatively long macro will do the same and store it in a dataset for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list_files(dir,ext);
	%local filrf rc did memcnt name i;
	%let rc=%sysfunc(filename(filrf,&amp;amp;dir));
	%let did=%sysfunc(dopen(&amp;amp;filrf));

	%if &amp;amp;did eq 0 %then
		%do;
			%put Directory &amp;amp;dir cannot be open or does not exist;

			%return;
		%end;

	%do i = 1 %to %sysfunc(dnum(&amp;amp;did));
		%let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

		%if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then
			%do;
				%put &amp;amp;dir\&amp;amp;name;
				%let file_name =  %qscan(&amp;amp;name,1,.);
				%put &amp;amp;file_name;

				data _tmp;
					length dir $512 name $100;
					dir=symget("dir");
					name=symget("name");
					path = catx('\',dir,name);
					the_name = substr(name,1,find(name,'.')-1);
				run;

				proc append base=list data=_tmp force;
				run;

				quit;

				proc sql;
					drop table _tmp;
				quit;

			%end;
		%else %if %qscan(&amp;amp;name,2,.) = %then
			%do;
				%list_files(&amp;amp;dir\&amp;amp;name,&amp;amp;ext)
			%end;
	%end;

	%let rc=%sysfunc(dclose(&amp;amp;did));
	%let rc=%sysfunc(filename(filrf));
%mend list_files;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;IMO this question is unreasonable&amp;nbsp;to expect an answer to all at once. You're better off trying it yourself and asking for help with specific portions. You seem to have the process mapped out so you should be able to find examples online or here for each section.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 02:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/358897#M274456</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-16T02:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: How to Look into folder/subfolder. Open and concatenate data files (if condition was satisf</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/897366#M354602</link>
      <description>&lt;P&gt;is it possible to check for any string within code and create a flag for that string if its have been in code. if yes can you help me how to incorporate within this code.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2023 11:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/897366#M354602</guid>
      <dc:creator>ManoharNath</dc:creator>
      <dc:date>2023-10-05T11:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: How to Look into folder/subfolder. Open and concatenate data files (if condition was satisf</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/897435#M354636</link>
      <description>You should probably start your own thread/post and include specific details. Depending on what you want, there's a variety of options to do what you want. And a few cases where it won't work (macro generated code).</description>
      <pubDate>Thu, 05 Oct 2023 17:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/897435#M354636</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-05T17:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: How to Look into folder/subfolder. Open and concatenate data files (if condition was satisf</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/897438#M354639</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17460"&gt;@ManoharNath&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;is it possible to check for any string within code and create a flag for that string if its have been in code. if yes can you help me how to incorporate within this code.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Other cases that may make a search for "string within code" not likely to succeed:&lt;/P&gt;
&lt;P&gt;Use of Call Execute creating code values from variables in a data set&lt;/P&gt;
&lt;P&gt;Using a data step to write additional code files&lt;/P&gt;
&lt;P&gt;Concatenation of variables/text into values you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you mean "check for a string the values of data set variables" that's another bit entirely.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2023 17:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-How-to-Look-into-folder-subfolder-Open-and-concatenate-data/m-p/897438#M354639</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-05T17:36:59Z</dc:date>
    </item>
  </channel>
</rss>

