<?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 extract an external file into a sas dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640037#M190525</link>
    <description>&lt;P&gt;So&lt;/P&gt;&lt;P&gt;1- in your input folder, you have many txt like "OnlineUsersxxxxxx.txt" (in Windows)&lt;/P&gt;&lt;P&gt;2- you want to import the lasted into a table SAS (in SAS) and create an copy and move to archived folder (in Windows)&lt;/P&gt;&lt;P&gt;3- with the table sas imported , you want to append with a table SAS historique existed (in SAS)&lt;/P&gt;&lt;P&gt;4- you want to delete the file externe aged over 30 day in the archived folder? (in Windows)&lt;/P&gt;&lt;P&gt;It s that you want?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 15 Apr 2020 08:31:23 GMT</pubDate>
    <dc:creator>kelxxx</dc:creator>
    <dc:date>2020-04-15T08:31:23Z</dc:date>
    <item>
      <title>How to extract an external file into a sas dataset in EG(windows)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640024#M190515</link>
      <description>&lt;P&gt;How can I extract the file “&lt;STRONG&gt;OnlineUsers&amp;lt;date&amp;gt;.txt&lt;/STRONG&gt;” in to a sas dataset into the location mentioned below:&lt;/P&gt;
&lt;P&gt;For the extraction I have to append all the related file in the input folder.&lt;/P&gt;
&lt;P&gt;A copy of the latest file will be moved into an Archive folder. Also in the archive folder any “&lt;STRONG&gt;OnlineUsers&amp;lt;date&amp;gt;.txt” &lt;/STRONG&gt;files with age more than 30 days are to be deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Input folder : /sas/sasdata/Lev1/External_Files/&lt;/P&gt;
&lt;P&gt;Output : /sas/sasteam/Lev1//Sales_MI&lt;/P&gt;
&lt;P&gt;Archive folder: /sas/sasdata/Lev1/External_Files/archive&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For now extract the file as this:&lt;/P&gt;
&lt;TABLE width="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="99"&gt;
&lt;P&gt;Username&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="73"&gt;
&lt;P&gt;Character&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="99"&gt;
&lt;P&gt;Forename&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="73"&gt;
&lt;P&gt;Character&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="99"&gt;
&lt;P&gt;Surname&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="73"&gt;
&lt;P&gt;Character&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="99"&gt;
&lt;P&gt;EmailAddress&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="73"&gt;
&lt;P&gt;Character&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="99"&gt;
&lt;P&gt;LastLoginDate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="73"&gt;
&lt;P&gt;Character&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;first few lines of one file in a text editor is,&lt;/P&gt;
&lt;P&gt;Username|Forename|Surname|EmailAddress|LastLoginDate|&lt;/P&gt;
&lt;P&gt;NULL|Alan|Brown|223440@cofundsmigration.co.uk|NULL&lt;/P&gt;
&lt;P&gt;paul@prosperity-ifa.co.uk|Paul|Bonomini|paul@prosperity-ifa.co.uk|Mar 30 2020 9:47AM&lt;/P&gt;
&lt;P&gt;colin@prosperity-ifa.co.uk|Colin|Fawcett|colin@prosperity-ifa.co.uk|Apr 3 2020 8:36AM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I have use the below code but nothing working.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;/filename users14 "/sas/sasdata/Lev1/External_Files/Cofunds_Files/mi/OnlineUsers20200414.txt";&lt;/P&gt;
&lt;P&gt;filename users10 "/sas/sasdata/Lev1/External_Files/Cofunds_Files/mi/OnlineUsers20200410.txt";&lt;/P&gt;
&lt;P&gt;/*onlineuser20200414.txt and onlineuser20200410.txt was present in that location after I search for it*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data user_data14;&lt;BR /&gt;infile users14;&lt;BR /&gt;input Username $&lt;BR /&gt;Forename $&lt;BR /&gt;Surname $&lt;/P&gt;
&lt;P&gt;Lastlogindate $;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data user_data10;&lt;BR /&gt;infile users10;&lt;BR /&gt;input Username $&lt;BR /&gt;Forename $&lt;BR /&gt;Surname $&lt;/P&gt;
&lt;P&gt;Lastlogindate $;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc append base=user_data10 data=user_data14;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename users pipe "/sas/sasdata/Lev1/External_Files/Cofunds_Files/mi/";&lt;BR /&gt;data files;&lt;BR /&gt;infile users truncover;&lt;BR /&gt;input filename $100.;&lt;BR /&gt;date = input(scan(scan(scan(filename,-1,'/'),1,'.'),3,'_'), mmddyy8.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=files;&lt;BR /&gt;by descending date;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set files;&lt;BR /&gt;call symput('infile',filename);&lt;BR /&gt;stop; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data archive;&lt;BR /&gt;format date mmddyy8.;&lt;BR /&gt;if date=today() then do;&lt;BR /&gt;fcopy("/sas/sasdata/Lev1/External_Files/Cofunds_Files/mi/", "/sas/sasdata/Lev1/External_Files/Cofunds_Files/mi/archive");&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;data delete;&lt;BR /&gt;format period yyyymmdd.;&lt;BR /&gt;x='20200414';&lt;/P&gt;
&lt;P&gt;y=filename(f-name, "physical-name");&lt;BR /&gt;if period=intck('month', x, -30, 'sameday') then do;&lt;/P&gt;
&lt;P&gt;fdelete(f-name)&lt;BR /&gt;end;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/&amp;gt;&lt;/P&gt;
&lt;P&gt;The above code is wrong and incomplete it more like a pseudo-code, can anybody help.&lt;/P&gt;
&lt;P&gt;EDITED&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 10:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640024#M190515</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T10:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640033#M190521</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;It s on Linux/Unix or Windows ?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 08:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640033#M190521</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-15T08:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640034#M190522</link>
      <description>&lt;P&gt;Open your text file with a text editor and copy/paste the first few lines into a window opened with &amp;lt;/&amp;gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 08:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640034#M190522</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-15T08:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640035#M190523</link>
      <description>windows</description>
      <pubDate>Wed, 15 Apr 2020 08:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640035#M190523</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T08:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640037#M190525</link>
      <description>&lt;P&gt;So&lt;/P&gt;&lt;P&gt;1- in your input folder, you have many txt like "OnlineUsersxxxxxx.txt" (in Windows)&lt;/P&gt;&lt;P&gt;2- you want to import the lasted into a table SAS (in SAS) and create an copy and move to archived folder (in Windows)&lt;/P&gt;&lt;P&gt;3- with the table sas imported , you want to append with a table SAS historique existed (in SAS)&lt;/P&gt;&lt;P&gt;4- you want to delete the file externe aged over 30 day in the archived folder? (in Windows)&lt;/P&gt;&lt;P&gt;It s that you want?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 08:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640037#M190525</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-15T08:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640038#M190526</link>
      <description>yes some of the files are with no timestamp also like userxyz.txt too but overall what you written is all I want</description>
      <pubDate>Wed, 15 Apr 2020 08:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640038#M190526</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T08:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640040#M190528</link>
      <description>username forename surname lastlogindate&lt;BR /&gt;abc@x      ab             c            20200412</description>
      <pubDate>Wed, 15 Apr 2020 08:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640040#M190528</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T08:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640042#M190530</link>
      <description>&lt;P&gt;So I copied your text into a file stored in my UE shared folder, and ran this code successfully:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data onlineusers20200415;
infile "/folders/myfolders/onlineusers20200415.txt" dlm=' ' firstobs=2 dsd truncover;
input username :$50. forename :$10. surname :$20. lastlogindate :yymmdd8.;
format lastlogindate yymmddd10.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2020 08:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640042#M190530</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-15T08:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset in EG(windows)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640048#M190535</link>
      <description>&lt;PRE&gt;/*===============Preparation================*/
%let input_folder=H:;
%let archi_folder=H:\archive;
%let output_folder=H:\output;
%let name_table_history=lib.xxx;

/*====delete file in archive folder ====*/
/*list of file in folder archive folder*/
Filename filesarc PIPE "dir /b &amp;amp;archi_folder";

data list_file_A_folder;
infile filesarc;
input namefile :$ 50.;
run;

/*delete*/
options noxwait;
data _null_;
set list_file_A_folder(where=(lowcase(namefile) like "onlineusers%.txt"));
_over30=put(date()-30,yymmddN.); /*date over 30*/
_dte=substr(namefile,12,8);/*date in filename*/
if _dte le _over30 then 
CALL SYSTEM(CAT("del /f /q"," ","&amp;amp;archi_folder.\",namefile));
run;

/*=======extract the name of lasted file onlineusers .txt end copy to archive folder======*/
/*list of file in folder input folder*/
Filename filesin PIPE "dir /b &amp;amp;input_folder";

data list_file_I_folder;
infile filesin;
input namefile :$ 50.;
run;

/*last file*/
data _null_;
set list_file_I_folder(where=(lowcase(namefile) like "onlineusers%.txt")) end=eof;
if eof then do;
call symput("lasted_file",cats(namefile));
call SYSTEM(cat("copy /y &amp;amp;input_folder.\",namefile," &amp;amp;archi_folder"));
end;
run;

%put &amp;amp;lasted_file;

%let nametab=%SCAN(&amp;amp;lasted_file,1,".");
%put &amp;amp;nametab;

Filename lastfile "&amp;amp;input_folder\&amp;amp;lasted_file";

/*==== import to table SAS ======*/
data &amp;amp;nametab;
infile lastfile dsd missover &amp;lt;other options ….&amp;gt;;
input 	Username $			/*add the informat in your data source*/
		Forename $
		Surname $
		Lastlogindate $;
run;

/*====append with the table SAS of history====*/
PROC APPEND data=&amp;amp;nametab base=&amp;amp;name_table_history ; QUIT;&lt;/PRE&gt;&lt;P&gt;Can you test it?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 09:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640048#M190535</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-15T09:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640058#M190541</link>
      <description>and how can I pregress with rest of the question? any idea sir?</description>
      <pubDate>Wed, 15 Apr 2020 10:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640058#M190541</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T10:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640060#M190542</link>
      <description>sir here is the first few lines,&lt;BR /&gt;Username|Forename|Surname|EmailAddress|LastLoginDate|&lt;BR /&gt;&lt;BR /&gt;NULL|Alan|Brown|223440@cofundsmigration.co.uk|NULL&lt;BR /&gt;&lt;BR /&gt;paul@prosperity-ifa.co.uk|Paul|Bonomini|paul@prosperity-ifa.co.uk|Mar 30 2020 9:47AM&lt;BR /&gt;&lt;BR /&gt;colin@prosperity-ifa.co.uk|Colin|Fawcett|colin@prosperity-ifa.co.uk|Apr 3 2020 8:36AM&lt;BR /&gt;&lt;BR /&gt;in the reply I did'nt checked the editor as it was unavailable, and can you modify your code?</description>
      <pubDate>Wed, 15 Apr 2020 10:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640060#M190542</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T10:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640065#M190543</link>
      <description>&lt;P&gt;Now this looks completely different than what you posted before.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;use a TEXT editor (e.g. the Windows Editor; just enter "editor" after clicking the Start button) to open your file; my preferred tool for working with text in Windows is Notepad++&lt;/LI&gt;
&lt;LI&gt;copy/paste the contents into a window opened with &amp;lt;/&amp;gt;:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.png"&gt;&lt;img src="https://communities.sas.com/skins/images/70F8802BAA6255D55FBEC62A8226FB10/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dlm='|' dsd truncover firstobs=2;
input
  Username :$50.
  Forename :$20.
  Surname :$50.
  EmailAddress :$50.
  LastLoginDate :ANYDTDTM20.
;
format lastlogindate e8601dt20.;
datalines;
Username|Forename|Surname|EmailAddress|LastLoginDate|
NULL|Alan|Brown|223440@cofundsmigration.co.uk|NULL
paul@prosperity-ifa.co.uk|Paul|Bonomini|paul@prosperity-ifa.co.uk|Mar 30 2020 9:47AM
colin@prosperity-ifa.co.uk|Colin|Fawcett|colin@prosperity-ifa.co.uk|Apr 3 2020 8:36AM
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to read your actual file, replace the keyword DATALINES in the INFILE statement with the path to your file (in quotes), and replace the datalines block with a run; statement.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 11:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640065#M190543</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-15T11:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640067#M190545</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316738"&gt;@annypanny&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;and how can I pregress with rest of the question? any idea sir?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We'll cover that once you have managed to read &lt;EM&gt;one&lt;/EM&gt; file successfully.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 11:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640067#M190545</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-15T11:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640102#M190566</link>
      <description>it is working for me now, as I have to extract all as character so I have used&lt;BR /&gt;LastLoginDate : $50. and not in datetime, it is mentioned in the question also.&lt;BR /&gt;Thank u for this sir, can we move forward?</description>
      <pubDate>Wed, 15 Apr 2020 13:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640102#M190566</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-15T13:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640109#M190572</link>
      <description>&lt;P&gt;Why would you want to store a datetime value as an ugly string that is unusable? You lose all of the functionality that SAS has built for handling date and time values.&lt;/P&gt;
&lt;P&gt;So I'll stay with using the datetime string as a datetime value.&lt;/P&gt;
&lt;P&gt;So we have code for one instance:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data yourlib.onlineusers200415;
infile "/location/onlineusers200415.txt" dlm='|' dsd truncover firstobs=2;
input
  Username :$50.
  Forename :$20.
  Surname :$50.
  EmailAddress :$50.
  LastLoginDate :ANYDTDTM20.
;
format lastlogindate e8601dt20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We want the filename to be variable, and determine the name of the dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fname=onlineusers200415;

data yourlib.&amp;amp;fname;
infile "/location/&amp;amp;fname..txt" dlm='|' dsd truncover firstobs=2;
input
  Username :$50.
  Forename :$20.
  Surname :$50.
  EmailAddress :$50.
  LastLoginDate :ANYDTDTM20.
;
format lastlogindate e8601dt20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which can quickly be turned into a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_one(fname);
data yourlib.&amp;amp;fname;
infile "/location/&amp;amp;fname..txt" dlm='|' dsd truncover firstobs=2;
input
  Username :$50.
  Forename :$20.
  Surname :$50.
  EmailAddress :$50.
  LastLoginDate :ANYDTDTM20.
;
format lastlogindate e8601dt20.;
run;
%mend;
%import_one(onlineusers200415)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's feed this macro from a list of files:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files;
length location $8;
rc = filename(location,"/location"); /* insert your path here */
did = dopen(location);
do i = 1 to dnum(did);
  name = dread(did,i);
  if substr(name,1,11) = "OnlineUsers" and scan(name,2,'.') = 'txt'
  /* adapt above condition as needed */
  then output;
end;
rc = dclose(did);
rc = filename(location);
keep name;
run;

data _null_;
set files;
call execute(cats('%nrstr(%import_one(',scan(name,1,'.'),'))'));
/* the scan() function removes the extension */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Care must be taken that the filenames of the source files (with the exception of the .txt extension) can be used as valid SAS names.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 13:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640109#M190572</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-15T13:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset in EG(windows)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640113#M190576</link>
      <description>&lt;P&gt;It s bizzare, i think that i posted my codes,&lt;/P&gt;&lt;P&gt;1.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*==== Preparation ===*/
%let input_folder=H:;
%let archive_folder=H:\Archive;
%let tab_history=libname.tabname;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*==== Delete files aged over 30 days in Archive ===*/
filename filesA PIPE "dir /B &amp;amp;archive_folder";

data file_in_A;
infile filesA;
input filename :$50.;
run;

option noxwait;
data _null_;
set file_in_A(where=(lowcase(filename) like "onlineusers%.txt"));
over30=put(date()-30,yymmddn.);
datefile=substr(filename,12,8);
if datefile le over30 then do;
call system(cat("del /f /q ","&amp;amp;archive_folder.\",filename));
end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;3.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*==== Copy lasted file ====*/
filename filesI PIPE "dir /B &amp;amp;input_folder";

data file_in_I;
infile filesI;
input filename :$50.;
run;

data _null_;
set file_in_I(where=(lowcase(filename) like "onlineusers%.txt")) end=eof;
if eof then do;
call symputx("last_file",filename);
call system(cat("copy ","&amp;amp;input_folder.\",filename," &amp;amp;archive_folder"));
end;
run;
%let nomtab=%SCAN(&amp;amp;last_file,1,".");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;4.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*==== import to table SAS====*/
data &amp;amp;nomtab;
infile "&amp;amp;input_folder.\&amp;amp;last_file." ......;
input .....;
run;

/*==== append with table history ====*/
proc append data=&amp;amp;nomtab base=&amp;amp;tab_history; quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2020 14:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640113#M190576</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-15T14:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640282#M190669</link>
      <description>yes all are correct and working for me but what if the filename changes dynamically, suppose yesterday date 15th april 2020 and the filename was OnlineUser20200415 now today I can't extract that file because a new file taken place instead of that i.e., OnlineUser20200416(today's date) and I want to solve it programmatically and not by changing the file name, How can I get that solved?</description>
      <pubDate>Thu, 16 Apr 2020 06:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640282#M190669</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-16T06:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640285#M190672</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316738"&gt;@annypanny&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;yes all are correct and working for me but what if the filename changes dynamically, suppose yesterday date 15th april 2020 and the filename was OnlineUser20200415 now today I can't extract that file because a new file taken place instead of that i.e., OnlineUser20200416(today's date) and I want to solve it programmatically and not by changing the file name, How can I get that solved?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This code from my last post&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data files;
length location $8;
rc = filename(location,"/location"); /* insert your path here */
did = dopen(location);
do i = 1 to dnum(did);
  name = dread(did,i);
  if substr(name,1,11) = "OnlineUsers" and scan(name,2,'.') = 'txt'
  /* adapt above condition as needed */
  then output;
end;
rc = dclose(did);
rc = filename(location);
keep name;
run;

data _null_;
set files;
call execute(cats('%nrstr(%import_one(',scan(name,1,'.'),'))'));
/* the scan() function removes the extension */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will read ALL files where the filename satisfies the condition in the data step that reads the directory. You n make your selection by changing the condition.&lt;/P&gt;
&lt;P&gt;Now, if you want to select the last in a series, you just sort properly and fetch the last entry:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=files;
by name;
run;
/* usually, this is not needed, as directories have their entries sorted anyway, but ... */

data _null_;
set files nobs=nobs point=nobs;
call execute(cats('%nrstr(%import_one(',scan(name,1,'.'),'))'));
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 06:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640285#M190672</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-16T06:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640296#M190682</link>
      <description>the above code is giving an error message&lt;BR /&gt;1         + %import_one()&lt;BR /&gt;            _&lt;BR /&gt;            180&lt;BR /&gt;WARNING: Apparent invocation of macro IMPORT_ONE not resolved.&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;&lt;BR /&gt;I just want to find out today's file and read that file into a dataset programically. My question is that&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640296#M190682</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-04-16T07:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an external file into a sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640299#M190684</link>
      <description>&lt;P&gt;You must run the macro definition before you can use the macro.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-external-file-into-a-sas-dataset-in-EG-windows/m-p/640299#M190684</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-16T07:35:37Z</dc:date>
    </item>
  </channel>
</rss>

