<?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: Stored Macro vars into a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140622#M28303</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Usually that's done in the other direction, read the list of files into a dataset and then store into macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a particular reason you're trying to do it the other way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming your on windows the following will work, if you're on unix then post back.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/820.html" title="http://support.sas.com/kb/24/820.html"&gt;24820 - Creating a Directory Listing Using SAS for Windows&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Jan 2014 16:08:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-01-14T16:08:08Z</dc:date>
    <item>
      <title>Stored Macro vars into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140619#M28300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a macro that gets all the file names from a folder and stores them as macro variables. I'm trying to take the stored macro variables and put them into a one column data set, this is causing me a lot of trouble. I've tried writing a loop to do this but i keep getting an error. Any help would be much appreciated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 15:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140619#M28300</guid>
      <dc:creator>Jsendzik</dc:creator>
      <dc:date>2014-01-14T15:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Stored Macro vars into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140620#M28301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let filecount=100;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*****************import the image filenames********************************************************;&lt;/P&gt;&lt;P&gt;%macro drive(dir,ext);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let filrf=mydir;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Assigns the fileref of mydir to the directory and opens the directory */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Returns the number of members in the directory */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let memcnt=%sysfunc(dnum(&amp;amp;did));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Loops through entire directory */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i = 1 %to &amp;amp;memcnt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Returns the extension from each file */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %global file&amp;amp;i.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let file&amp;amp;i. = %qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Checks to see if file contains an extension */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Checks to see if the extension matches the parameter value */&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* If condition is true prints the full name to the log */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if (%superq(ext) ne and %qupcase(&amp;amp;name) = %qupcase(&amp;amp;ext)) or&lt;/P&gt;&lt;P&gt;&amp;nbsp; (%superq(ext) = and %superq(name) ne) %then&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Closes the directory */&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let rc=%sysfunc(dclose(&amp;amp;did));&lt;/P&gt;&lt;P&gt;%mend drive;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code right now. It's making the macro vars variable names and not observations.&lt;/P&gt;&lt;P&gt;%macro newsets(); &lt;/P&gt;&lt;P&gt;data outloops; &lt;/P&gt;&lt;P&gt;%do i = 1 %to 100; &lt;/P&gt;&lt;P&gt;files = %substr(&amp;amp;&amp;amp;file&amp;amp;i.,1,10); &lt;/P&gt;&lt;P&gt;%end; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;%mend; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%newsets; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 15:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140620#M28301</guid>
      <dc:creator>Jsendzik</dc:creator>
      <dc:date>2014-01-14T15:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Stored Macro vars into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140621#M28302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jsendzik,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I faced a similar problem to you and created the below code to solve it. I had been using the pipe statement but wanted to have the dir file location directly inserted so I wouldn't have to write it out and this was the code that ended up working. The link to my question is &lt;A __default_attr="51795" __jive_macro_name="thread" class="jive_macro jive_macro_thread" href="https://communities.sas.com/"&gt;&lt;/A&gt; it also includes some other options to do the same thing. Of note if you want to do anything with the file names you likely will need to use a %scan function, but that is for another time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let source = C:\User /*Insert your drive path*/;&lt;/P&gt;&lt;P&gt;%macro read_files (type = ); /*type is the extension of the files you want to keep, ie csv txt*/&lt;/P&gt;&lt;P&gt;filename _dir_ "%bquote(&amp;amp;source.)";&lt;/P&gt;&lt;P&gt;data filenames(keep=memname);&lt;/P&gt;&lt;P&gt;&amp;nbsp; handle=dopen( '_dir_' );&lt;/P&gt;&lt;P&gt;&amp;nbsp; if handle &amp;gt; 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count=dnum(handle);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname=dread(handle,i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output filenames;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; rc=dclose(handle);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;filename _dir_ clear;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dirlist ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set filenames;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(memname,length(memname)-2,3) ~="&amp;amp;type" then delete;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file_name = substr(memname,1,length(memname)-4);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep file_name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 15:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140621#M28302</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2014-01-14T15:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Stored Macro vars into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140622#M28303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Usually that's done in the other direction, read the list of files into a dataset and then store into macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a particular reason you're trying to do it the other way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming your on windows the following will work, if you're on unix then post back.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/820.html" title="http://support.sas.com/kb/24/820.html"&gt;24820 - Creating a Directory Listing Using SAS for Windows&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 16:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140622#M28303</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-01-14T16:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Stored Macro vars into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140623#M28304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Given that your first macro is working, and given that you are willing to hard-code the number of files instead of automating that part, your loop should be fairly easy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro newsets;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; data dirlist;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length filename $ 80;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %local i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %do i=1 %to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename = "&amp;amp;&amp;amp;file&amp;amp;i";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend newsets;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course,&amp;nbsp; you can always turn the number of files, or the output data set name, into a macro parameter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 16:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140623#M28304</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-01-14T16:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Stored Macro vars into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140624#M28305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jan 2014 16:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stored-Macro-vars-into-a-dataset/m-p/140624#M28305</guid>
      <dc:creator>Jsendzik</dc:creator>
      <dc:date>2014-01-14T16:37:53Z</dc:date>
    </item>
  </channel>
</rss>

