<?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: Is it possible to get the name of the file (to be used for infile statement) from a dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674772#M203226</link>
    <description>&lt;P&gt;So the dataset you got from the directory should look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fnames;
infile datalines dlm=',';
input fname :$200. product :$12.;
datalines;
PROD.CNTR_PRODUCT1.DATA.20200630.csv.20200717.191521,PRODUCT1
PROD.CNTR_PRODUCT2.DATA.20200630.csv.20200717.183024,PRODUCT2
PROD.CNTR_PRODUCT3.DATA.20200630.csv.20200717.193743,PRODUCT3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can read everything into one dataset with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_products;
set fnames;
fname = "&amp;amp;stout.\" !! trim(fname);
infile dummy filevar=fname dlm="|" end=done; /* add additional options as necessary */
do until (done);
  input
    acct_id :$30.
    column2 :4.
    column3 :$6.
    bal :20.
  ;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The product will be automatically set from the dataset FNAMES.&lt;/P&gt;
&lt;P&gt;After this, you can perform all calculations from this comprehensive dataset.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Aug 2020 16:31:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-08-05T16:31:04Z</dc:date>
    <item>
      <title>Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674644#M203165</link>
      <description />
      <pubDate>Wed, 05 Aug 2020 04:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674644#M203165</guid>
      <dc:creator>DritanB</dc:creator>
      <dc:date>2020-08-05T04:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674651#M203168</link>
      <description>&lt;P&gt;No. The dataset has no information how it was created.&lt;/P&gt;
&lt;P&gt;Unless someone did the extra work to store this (manually) in the dataset label.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 05:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674651#M203168</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T05:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674661#M203172</link>
      <description>&lt;P&gt;I am not sure i understand what you mean. If you have a dataset and want know which file was read to create the dataset, then &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; already gave the answer. If have list of files in a dataset and want to read them: yes that is possible, have a look at the documentation of the infile-statement. especially the filevar-option.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 08:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674661#M203172</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-05T08:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674665#M203173</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;has a point here; this would look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data filenames;
input fname $50.;
datalines;
filename1
filename2
filename3
;

data all;
set filenames;
infile dummy filevar=fname end=done;
do until (done);
  input var1 var2 var3;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;see the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;INFILE Statement&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 08:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674665#M203173</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T08:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674725#M203200</link>
      <description>&lt;P&gt;Hi, thank you for your input!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I am trying to do (sorry did not provide more details in my original post last night):&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- In a folder (Windows), I have a list a of csv files; their filenames contain specific keywords (representing what product they are), the month end date (for example: 20200630) and date/time stamp when they were created (for example: 20200710.180656).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The structure of these filenames within this folder is as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT1.DATA.20200630.csv.20200717.174612&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT1.PARAMETER.20200630.csv.20200717.180610&lt;/P&gt;&lt;P&gt;PROD.APPtriggerfile.PROD - Dept.CNTR_PRODUCT1.20200630.csv.20200717.180615&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT2.DATA.20200630.csv.20200717.183024&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT2.PARAMETER.20200630.csv.20200717.184315&lt;/P&gt;&lt;P&gt;PROD.APPtriggerfile.PROD - Dept.CNTR_PRODUCT2.20200630.csv.20200717.184320&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT3.DATA.20200630.csv.20200717.184942&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT3.PARAMETER.20200630.csv.20200717.190211&lt;/P&gt;&lt;P&gt;PROD.APPtriggerfile.PROD - Dept.CNTR_PRODUCT3.20200630.csv.20200717.190216&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT1.DATA.20200630.csv.20200717.191521&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT1.PARAMETER.20200630.csv.20200717.193221&lt;/P&gt;&lt;P&gt;PROD.APPtriggerfile.PROD - Dept.CNTR_PRODUCT1.20200630.csv.20200717.193226&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT3.DATA.20200630.csv.20200717.193743&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT3.PARAMETER.20200630.csv.20200717.194201&lt;/P&gt;&lt;P&gt;PROD.APPtriggerfile.PROD - Dept.CNTR_PRODUCT3.20200630.csv.20200717.194206&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Task 1:&lt;BR /&gt;Out of hundreds of these files in this folder, I have to select very few (about 19); these files should be:&lt;/P&gt;&lt;P&gt;- only DATA files,&lt;/P&gt;&lt;P&gt;- only for specific products as per specified list (Product1, 2...)&lt;/P&gt;&lt;P&gt;- only the latest created files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to do this and I have created a dataset with two column: one containing the full filename and the other containing only the respective product name (if needed I can include other information like month-end-date, datestamp, timestamp...):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT1.DATA.20200630.csv.20200717.191521&lt;/P&gt;&lt;P&gt;PRODUCT1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT2.DATA.20200630.csv.20200717.183024&lt;/P&gt;&lt;P&gt;PRODUCT2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROD.CNTR_PRODUCT3.DATA.20200630.csv.20200717.193743&lt;/P&gt;&lt;P&gt;PRODUCT3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Task 2: I have to:&lt;BR /&gt;a - import them as sas datasets (they are csv files)&lt;BR /&gt;b - perform some calculations with some of the data contained in these datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The generic code for Task 2/b is as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET STOUT=\\NAS_SHARED_LOCATION\Folder1\Folder2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro calc(lbl=);&lt;/P&gt;&lt;P&gt;/*Reading csv files into dataset*/&lt;/P&gt;&lt;P&gt;data work.incsv;&lt;BR /&gt;infile "&amp;amp;STOUT\&amp;amp;flname" dlm='|,' dsd firstobs=2;&lt;BR /&gt;input acct_id :$30.&lt;BR /&gt;column2 :4.&lt;BR /&gt;column3 :$6.&lt;BR /&gt;bal :20.&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Creating the results*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table outreslt as&lt;BR /&gt;select "&amp;amp;lbl" as Product length=12 label='Product',&lt;BR /&gt;count(*) as Total_Records format=comma10. label='Total Count',&lt;BR /&gt;sum(bal) as Total_BAL format=dollar16. label='Total Amount'&lt;BR /&gt;from work.incsv;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Updating Results*/&lt;/P&gt;&lt;P&gt;data Output_results;&lt;BR /&gt;set Output_results outreslt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend calc;&lt;/P&gt;&lt;P&gt;%calc(lbl="Product1");&lt;BR /&gt;%calc(lbl="Product2");&lt;BR /&gt;%calc(lbl="Product3");&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;%calc(lbl="Product19");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Printing Results*/&lt;/P&gt;&lt;P&gt;proc print data=Output_results;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is about Task 2/a: is it possible to pass the values from the dataset created in Task 1 to the infile statement used in Task 2/b, specicilally to &amp;amp;flname variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 14:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674725#M203200</guid>
      <dc:creator>DritanB</dc:creator>
      <dc:date>2020-08-05T14:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674772#M203226</link>
      <description>&lt;P&gt;So the dataset you got from the directory should look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fnames;
infile datalines dlm=',';
input fname :$200. product :$12.;
datalines;
PROD.CNTR_PRODUCT1.DATA.20200630.csv.20200717.191521,PRODUCT1
PROD.CNTR_PRODUCT2.DATA.20200630.csv.20200717.183024,PRODUCT2
PROD.CNTR_PRODUCT3.DATA.20200630.csv.20200717.193743,PRODUCT3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can read everything into one dataset with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_products;
set fnames;
fname = "&amp;amp;stout.\" !! trim(fname);
infile dummy filevar=fname dlm="|" end=done; /* add additional options as necessary */
do until (done);
  input
    acct_id :$30.
    column2 :4.
    column3 :$6.
    bal :20.
  ;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The product will be automatically set from the dataset FNAMES.&lt;/P&gt;
&lt;P&gt;After this, you can perform all calculations from this comprehensive dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 16:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674772#M203226</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T16:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to get the name of the file (to be used for infile statement) from a dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674826#M203243</link>
      <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was also able to modify my code, by entering a proc sql on top of the macro &lt;SPAN&gt;calc (before reading the datasets)&amp;nbsp;&lt;/SPAN&gt;and introducing the variable (which I used in INFILE statement) inside this proc sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro calc(lbl=);&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select file_name&lt;BR /&gt;into :fname&lt;BR /&gt;from latest_filenames&lt;BR /&gt;where segment = &amp;amp;lbl.;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Reading csv files into dataset*/&lt;/P&gt;&lt;P&gt;data work.incsv;&lt;BR /&gt;infile "&amp;amp;STOUT.\&amp;amp;fname." dlm='|,' dsd firstobs=2;&lt;/P&gt;&lt;P&gt;input acct_id :$30.&lt;BR /&gt;column2 :4.&lt;BR /&gt;column3 :$6.&lt;BR /&gt;bal :20.&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Perform calculations*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Update results dataset*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend calc;&lt;BR /&gt;%calc(lbl='PRODUCT1');&lt;BR /&gt;%calc(lbl='PRODUCT2');&lt;BR /&gt;%calc(lbl='PRODUCT3');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 19:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-get-the-name-of-the-file-to-be-used-for-infile/m-p/674826#M203243</guid>
      <dc:creator>DritanB</dc:creator>
      <dc:date>2020-08-05T19:02:38Z</dc:date>
    </item>
  </channel>
</rss>

