<?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 files with different names, infile, then export? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770038#M244231</link>
    <description>&lt;P&gt;I got this far:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname cookies "C:\Output_filepath";

%let cook_file = C:\Data_filepath;

%macro file_yr (year=year);

data cookies.cookies-&amp;amp;year.;
/* wondering about this statement */

infile "&amp;amp;cook_file.\cookies-&amp;amp;year..txt"

	firstobs = 2 dlm="|" lrecl=32767 missover truncover dsd;

/* inserted attributes/field headers here
input
;

format
inserted formatting for variables here as well
;
*/

run;
%mend;

%file_yr 			(year=2015);
%file_yr 			(year=2016);
%file_yr 			(year=2017);
%file_yr 			(year=2018);
/* unsure how to change the %fire_yr here to accommodate for the "Updated" files*/

/* Stack all years */
data cookies_All_Years;
	set 
Cookies.cookies_2015
Cookies.cookies_2016
Cookies.cookies_2017
Cookies.cookies_2018
;
run;

/* record count check */
proc sql;
	create table cookies_cnts as
	select year,
    count (*) as Num_Records
from   cookies_all_years
group by year
;
quit;

proc export 
  data=cookies_cnts
  dbms=xlsx 
  outfile="C:\cookie record counts.xlsx"
  replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Sep 2021 20:28:12 GMT</pubDate>
    <dc:creator>leeleelee</dc:creator>
    <dc:date>2021-09-23T20:28:12Z</dc:date>
    <item>
      <title>How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/769814#M244127</link>
      <description>&lt;P&gt;Hello, I have the following files in [location] that are named:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;cookies-2015_updated&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;cookies-2016_updated&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;cookies-2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;cookies2018&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;How do I infile these to:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN style="font-family: inherit;"&gt;Make sure the individual files get exported to individual sas datasets?&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Export excel file with record counts using proc sql?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I would like to have this in one sas program, not 2 separate ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 08:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/769814#M244127</guid>
      <dc:creator>leeleelee</dc:creator>
      <dc:date>2021-09-23T08:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/769857#M244142</link>
      <description>&lt;P&gt;What have you tried so far? Where did you get stuck?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If asking for code please provide sample data and clearly show how the desired output using the sample data should look like.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 09:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/769857#M244142</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-23T09:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770038#M244231</link>
      <description>&lt;P&gt;I got this far:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname cookies "C:\Output_filepath";

%let cook_file = C:\Data_filepath;

%macro file_yr (year=year);

data cookies.cookies-&amp;amp;year.;
/* wondering about this statement */

infile "&amp;amp;cook_file.\cookies-&amp;amp;year..txt"

	firstobs = 2 dlm="|" lrecl=32767 missover truncover dsd;

/* inserted attributes/field headers here
input
;

format
inserted formatting for variables here as well
;
*/

run;
%mend;

%file_yr 			(year=2015);
%file_yr 			(year=2016);
%file_yr 			(year=2017);
%file_yr 			(year=2018);
/* unsure how to change the %fire_yr here to accommodate for the "Updated" files*/

/* Stack all years */
data cookies_All_Years;
	set 
Cookies.cookies_2015
Cookies.cookies_2016
Cookies.cookies_2017
Cookies.cookies_2018
;
run;

/* record count check */
proc sql;
	create table cookies_cnts as
	select year,
    count (*) as Num_Records
from   cookies_all_years
group by year
;
quit;

proc export 
  data=cookies_cnts
  dbms=xlsx 
  outfile="C:\cookie record counts.xlsx"
  replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Sep 2021 20:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770038#M244231</guid>
      <dc:creator>leeleelee</dc:creator>
      <dc:date>2021-09-23T20:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770074#M244247</link>
      <description>&lt;P&gt;Would below do what you're after?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* create sample data */
%let cook_file = C:\temp;
filename sample "&amp;amp;cook_file";
data _null_;
  file sample(cookies-2015_updated.txt);
  put 'colA|colB';
  put 'valueA|123';
  file sample(cookies-2016.txt);
  put 'colA|colB';
  put 'valueA|456';
  put 'valueA|456';
  file sample(cookies-2017.txt);
  put 'colA|colB';
  put 'valueA|789';
  put 'valueA|789';
  put 'valueA|789';
run;


/* proposed code based on posted one*/

libname cookies "C:\temp";
%let cook_file = C:\temp;

data cookies_All_Years;
  length _ThisFile $100;
  infile "&amp;amp;cook_file.\cookies-*.txt" dlm="|" lrecl=32767 truncover dsd filename=_ThisFile;
  input @;

  /* skip first line of a new input file */
  if lag(_ThisFile) ne _ThisFile then delete;

  /* read data */
  input colA $ colB;
  Source_File=_ThisFile;
run;

proc sql;
	create table cookies_cnts as
	select Source_File,
    count (*) as Num_Records
  from   cookies_all_years
  group by Source_File
;
quit;

data cookies_All_Years;
  merge cookies_All_Years cookies_cnts;
  by Source_File;
  Year=input(compress(scan(Source_File,-2,'\/-.'),'kd'),4.);
run;

proc export 
  data=cookies_cnts
  dbms=xlsx 
  outfile="C:\temp\cookie_record_counts.xlsx"
  replace;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Sep 2021 22:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770074#M244247</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-23T22:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770100#M244258</link>
      <description>&lt;P&gt;This works, but can you help me find a way to export something like this?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="leeleekim_0-1632459729122.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64025i5C42AC316692E54D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="leeleekim_0-1632459729122.png" alt="leeleekim_0-1632459729122.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 05:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770100#M244258</guid>
      <dc:creator>leeleelee</dc:creator>
      <dc:date>2021-09-24T05:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770115#M244270</link>
      <description>&lt;P&gt;The code I've posted already creates an Excel as below. Look into the scan() function if you only want to keep the file name and not path and file name.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1632463443299.png" style="width: 477px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64026iADC5BE45937F5F0C/image-dimensions/477x111?v=v2" width="477" height="111" role="button" title="Patrick_0-1632463443299.png" alt="Patrick_0-1632463443299.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw: If you don't need the detail data then you wouldn't need to create the table with all the detail but you would just count rows there and output whenever a new file starts or the very last record gets read (end=_last in the infile statement would allow to create such an end of data indicator).&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 06:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770115#M244270</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-24T06:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770124#M244277</link>
      <description>&lt;P&gt;On UNIX/Linux, I'd simply do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files;
infile "wc -l &amp;amp;path./cookie*" pipe;
input filename :$200. count;
run;

proc export
  data=files
  file="path_to_result.xlsx"
  dbms=xlsx
  replace
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Sep 2021 06:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770124#M244277</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-24T06:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get files with different names, infile, then export?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770127#M244279</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count=Count-1; to exclude the header row.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 06:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-files-with-different-names-infile-then-export/m-p/770127#M244279</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-24T06:48:53Z</dc:date>
    </item>
  </channel>
</rss>

