<?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: folder reading by macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637708#M189581</link>
    <description>Could you give some more detailed example? I'm not sure if I correctly understood your request.&lt;BR /&gt;&lt;BR /&gt;Do you have folder like: "C:\my_folder\my_subfolder2019-05-10" and want to read data set from that folder?&lt;BR /&gt;&lt;BR /&gt;Bart</description>
    <pubDate>Sun, 05 Apr 2020 16:59:49 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-04-05T16:59:49Z</dc:date>
    <item>
      <title>folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637705#M189578</link>
      <description>&lt;P&gt;Hi, I have 5 folders with different dates which have some sas datasets.&lt;/P&gt;
&lt;P&gt;trying to read the folder so that later i can pick the sas dataset of&amp;nbsp; m interest.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;below code throws an errors.&lt;/P&gt;
&lt;P&gt;ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC &lt;BR /&gt;or %QSYSFUNC function reference is terminated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let dt=%sysfunc(putn("2019-05-10"d, yymmdd10.)); &lt;BR /&gt;%put &amp;amp;dt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any ideas how to read folders with yyyy-mm-dd format to pick the sas datasets ?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 16:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637705#M189578</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-05T16:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637706#M189579</link>
      <description>&lt;P&gt;Wrong date format, try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=%sysfunc(putn("10may2019"d, yymmdd10.));
%put &amp;amp;dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS date literal is in the format "DDMmmYYYY"d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 16:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637706#M189579</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-05T16:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637707#M189580</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;,&lt;BR /&gt;Folders i have are in YYYY-MM-DD eg: 2019-05-10. Is there any other way out to read the folder and pick the dataset of my interest or shall i convert the folder name to 10may2019 by applying date9.? Kindly suggest&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 05 Apr 2020 16:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637707#M189580</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-05T16:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637708#M189581</link>
      <description>Could you give some more detailed example? I'm not sure if I correctly understood your request.&lt;BR /&gt;&lt;BR /&gt;Do you have folder like: "C:\my_folder\my_subfolder2019-05-10" and want to read data set from that folder?&lt;BR /&gt;&lt;BR /&gt;Bart</description>
      <pubDate>Sun, 05 Apr 2020 16:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637708#M189581</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-05T16:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637709#M189582</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=%sysfunc(putn("10may2019"d, yymmddd10.));
%put &amp;amp;=dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;produces the result 2019-05-10&lt;/P&gt;
&lt;P&gt;that's what you want, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637709#M189582</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-05T17:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637710#M189583</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;, Thanks for your concern. i have 6 folders "C:\my_folder\my_subfolder\2019-05-10" to "C:\my_folder\my_subfolder\2019-11-10" . Every folder contains some ****.sas7bdat datasets. I'm in the process of creating a macro to pick 2 .sas7bdat dataset  of my interest from each folder which is required for merging in later stage.&lt;BR /&gt;&lt;BR /&gt;so, i was trying to use %let dt=%sysfunc(putn("2019-05-10"d, yymmdd10.)) for start date to use it in do loop. but some how error comes up because the date is not being read by sas. Hope I'm clear. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637710#M189583</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-05T17:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637712#M189585</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109034"&gt;@sahoositaram555&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;did you even try running the code from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; or myself above, it seems to give you exactly what you are asking for.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637712#M189585</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-05T17:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637714#M189587</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try with this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* generate test data in folders */

options dlcreatedir;
libname x "C:\my_folder\";
libname x "C:\my_folder\my_subfolder\";
libname x "C:\my_folder\my_subfolder\2019-05-10"; 
data x.class1; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-06-10";
data x.class2; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-07-10";
data x.class3; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-08-10";
data x.class4; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-09-10";
data x.class5; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-10-10";
data x.class6; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-11-10";
data x.class7; set sashelp.class; run;
libname x clear;


/* macro-loop to assign libraries */

%macro generateLibrary(start, number);

%do i = 1 %to &amp;amp;number.;
  %let dt=%sysfunc(intnx(month, &amp;amp;start.,%eval(&amp;amp;i. - 1) ,S), yymmdd10.);
  libname lib&amp;amp;i "C:\my_folder\my_subfolder\&amp;amp;dt.";
%end;

%mend generateLibrary;

%generateLibrary('10may2019'd, 7);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and adopt it to your needs&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637714#M189587</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-05T17:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637715#M189588</link>
      <description>&lt;P&gt;To use a date literal,&amp;nbsp; "xxxxxx"d, the string inside the quotes needs to be something that the DATE informat can understand.&amp;nbsp; Your mistake is trying to use year month day style strings as date literals.&amp;nbsp; If you already have the date in yymmdd10 style then you don't need to use the PUTN() function call at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=2019-05-10;
libname want "c:\my_folder\my_subfolder\&amp;amp;dt" ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637715#M189588</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-05T17:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637716#M189589</link>
      <description>&lt;P&gt;Well, that's so simple its frightening. Why didn't I think of that?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637716#M189589</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-05T17:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637718#M189591</link>
      <description>Thank you both &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; for your thoughts .&lt;BR /&gt;I actually have them in YYYY-MM-DD format. The errors i was getting as i was using them in %let statement without quotes.&lt;BR /&gt;Thanks for making me clarify on this.&lt;BR /&gt;</description>
      <pubDate>Sun, 05 Apr 2020 17:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637718#M189591</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-05T17:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637724#M189595</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;, Thank you for sharing a sample code. I should have mentioned it before that the difference isn't one. Though i know that in my last post i had mentioned 2019-05-10 to 2019-11-10, but it's not exactly with of equal difference(-1) between folders. The difference varies.   &lt;BR /&gt;i understand the statement %let dt=%sysfunc(intnx(month, &amp;amp;start.,%eval(&amp;amp;i. - 1) ,S), yymmdd10.); will only work when difference of folders are only a month. &lt;BR /&gt;So, any other way of dealing this if the difference between folders not consistent,unlike 1 month as assumed? &lt;BR /&gt;And it throws error when the library names generated from the statement libname lib&amp;amp;i "C:\my_folder\my_subfolder\&amp;amp;dt."; is taken for any further proc process. &lt;BR /&gt;eg: instead of C:\my_folder\my_subfolder\  the sample i have is&lt;BR /&gt; "\\XXX-sas-zz1\my_folder\sub_folder. So when i use a procedure &lt;BR /&gt;proc sort data=lib.&amp;amp;i;by PatientInitials;run; it throws error as i have \\XXX-sas-zz1 and due to the "-" delimiters sas is unable to recognize the path and throws error.</description>
      <pubDate>Sun, 05 Apr 2020 19:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637724#M189595</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-05T19:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637726#M189596</link>
      <description>&lt;P&gt;It is hard to give an answer when you haven't explained the actual problem.&lt;/P&gt;
&lt;P&gt;If you know the folder names then just use them.&lt;/P&gt;
&lt;P&gt;Are you saying you don't know the folder names and you need to try to figure them out?&lt;/P&gt;
&lt;P&gt;Can't you just ask the operating system to tell you?&amp;nbsp; If you are using Windows then use DIR command, if Unix then ls command. Read the output into a dataset and you know the folder names.&lt;/P&gt;
&lt;P&gt;If you cannot do that (perhaps the NOXCMD option is set?) and you want to find all of the folders for a range of dates then just loop over that range of dates and check if the folder exists.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do date=%sysevalf("01MAY2018"d) %to %sysevalf("01JAN2010"d);
  %let dt=%sysfunc(putn(&amp;amp;date,yymmdd10.));
  %let path=c:\myfolders\&amp;amp;dt ;
  %if %sysfunc(fileexist("&amp;amp;path")) %then %do;
    .... what ever you need to do when you find one ...
  %end;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 20:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637726#M189596</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-05T20:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637805#M189626</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109034"&gt;@sahoositaram555&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) You can create a list of subFolders like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* generate test data in folders */

options dlcreatedir;
libname x "C:\my_folder\";
libname x "C:\my_folder\my_subfolder\";
data x.class01 x.class02 x.class03; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-05-10"; 
data x.class1; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-06-10";
data x.class2; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-07-10";
data x.class3; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-08-10";
data x.class4; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-09-10";
data x.class5; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-10-10";
data x.class6; set sashelp.class; run;
libname x "C:\my_folder\my_subfolder\2019-11-10";
data x.class7; set sashelp.class; run;
libname x clear;

/* extract the list of subdirectories */

data exactFolderNames;
   length exactFolderName $ 512;
   keep exactFolderName;
   base = "C:\my_folder\my_subfolder";

   rc=filename("_TMP_", base);
   did=dopen("_TMP_"); 

   do i = 1 to dnum(did);
        subfolder = dread(did, i);
        
        rc = filename("_sTMP_", catx("/", base, subfolder));
        subdid = dopen("_sTMP_");
        if subdid = 0 then continue; /* to ignore files */
 
        /* put (_all_) (=/) / ;*/
        exactFolderName = dinfo(subdid, "Directory");
        output;
        rc = dclose(subdid);
        rc = filename("_sTMP_");
   end;

   did=dclose(did);
   rc=filename("_TMP_");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 08:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637805#M189626</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-06T08:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: folder reading by macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637841#M189648</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109034"&gt;@sahoositaram555&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I have 5 folders with different dates which have some sas datasets.&lt;/P&gt;
&lt;P&gt;trying to read the folder so that later i can pick the sas dataset of&amp;nbsp; m interest.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;below code throws an errors.&lt;/P&gt;
&lt;P&gt;ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC &lt;BR /&gt;or %QSYSFUNC function reference is terminated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let dt=%sysfunc(putn("2019-05-10"d, yymmdd10.)); &lt;BR /&gt;%put &amp;amp;dt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any ideas how to read folders with yyyy-mm-dd format to pick the sas datasets ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You do not need to read the directory to get the names of SAS datasets. Assign a library to the directory and query DICTIONARY.TABLES (or SAHELP.VTABLE).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see what your problem is, and how it can be avoided, see this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt=%sysfunc(putn("10may2019"d, yymmdd10.)); 
%put &amp;amp;dt;
%let dt=%sysfunc(putn(%sysfunc(inputn(2019-05-10,yymmdd10.)),yymmddd10.)); 
%put &amp;amp;dt;
%let dt=2019-05-10;
%put &amp;amp;dt.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All three assignments create the same result.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 13:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/folder-reading-by-macro/m-p/637841#M189648</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-06T13:18:28Z</dc:date>
    </item>
  </channel>
</rss>

