<?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 Macro for .txt file with no header and Datasets for each file in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740409#M29055</link>
    <description>&lt;P&gt;I have multiple raw files without header . I want to automate the process in order to create multiples datasets and also once the dataset created need to automate the process when we use logic say&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;**Actvity_flag ='Y'**&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;, I need those datasets to be created which has data in it. No need of datasets with Null Rows.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Below is the Sample Text file&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;A_Sample.txt
B_Sample.txt
C_Sample.txt
D_Sample.txt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Path: C:\Data\datasets*****.txt&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Below are the Variables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Id 1-16&lt;/P&gt;&lt;P&gt;First_Name 17-27&lt;/P&gt;&lt;P&gt;Last-named 28-47&lt;/P&gt;&lt;P&gt;Phone_no 48-58&lt;/P&gt;&lt;P&gt;Activity_Flag 59-59&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data in text file look like as below&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;10001   George  Michael 123456789   Y
10002   Henry   Jha     987456123   Y
10003   Rob     Camer   258963147   N
10004   Allan   Cruze   369852147   Y
10005   Andy    wilson  147258369   N&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 08:53:45 GMT</pubDate>
    <dc:creator>Andysas9</dc:creator>
    <dc:date>2021-05-11T08:53:45Z</dc:date>
    <item>
      <title>Macro for .txt file with no header and Datasets for each file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740409#M29055</link>
      <description>&lt;P&gt;I have multiple raw files without header . I want to automate the process in order to create multiples datasets and also once the dataset created need to automate the process when we use logic say&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;**Actvity_flag ='Y'**&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;, I need those datasets to be created which has data in it. No need of datasets with Null Rows.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Below is the Sample Text file&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;A_Sample.txt
B_Sample.txt
C_Sample.txt
D_Sample.txt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Path: C:\Data\datasets*****.txt&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Below are the Variables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Id 1-16&lt;/P&gt;&lt;P&gt;First_Name 17-27&lt;/P&gt;&lt;P&gt;Last-named 28-47&lt;/P&gt;&lt;P&gt;Phone_no 48-58&lt;/P&gt;&lt;P&gt;Activity_Flag 59-59&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data in text file look like as below&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;10001   George  Michael 123456789   Y
10002   Henry   Jha     987456123   Y
10003   Rob     Camer   258963147   N
10004   Allan   Cruze   369852147   Y
10005   Andy    wilson  147258369   N&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 08:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740409#M29055</guid>
      <dc:creator>Andysas9</dc:creator>
      <dc:date>2021-05-11T08:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for .txt file with no header and Datasets for each file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740413#M29056</link>
      <description>&lt;P&gt;Rule #1 of macro development: start with working non-macro code.&lt;/P&gt;
&lt;P&gt;So please show us the code you use to create one text file from one dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Correction: one dataset from one text file.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 09:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740413#M29056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-11T09:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for .txt file with no header and Datasets for each file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740438#M29057</link>
      <description>Below is the code I used for each text file&lt;BR /&gt;data A_Sample;&lt;BR /&gt;infile 'C:\data\datasets\A_Sample.txt';&lt;BR /&gt;input&lt;BR /&gt;ID 1-16&lt;BR /&gt;FIRST_NAME $17-27&lt;BR /&gt;LAST_NAME $28 - 47&lt;BR /&gt;Phone_no 48 - 58&lt;BR /&gt;Activity_flag $59 - 59&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Proc Sql;&lt;BR /&gt;create tabe A_Sample_test as&lt;BR /&gt;select * from A_Sample where Activity_flag = 'Y';&lt;BR /&gt;Quit;</description>
      <pubDate>Tue, 11 May 2021 12:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740438#M29057</guid>
      <dc:creator>Andysas9</dc:creator>
      <dc:date>2021-05-11T12:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for .txt file with no header and Datasets for each file</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740459#M29066</link>
      <description>&lt;P&gt;So you need to replace all occurrences of A_Sample with a macro variable, and then wrapthe code into a macro that accepts a parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_text(fname);

data &amp;amp;fname.;
infile "C:\data\datasets\&amp;amp;fname..txt";
input
  ID 1-16
  FIRST_NAME $17-27
  LAST_NAME $28 - 47
  Phone_no 48 - 58
  Activity_flag $59 - 59
;

Proc Sql;
create table &amp;amp;fname._test as
select * from &amp;amp;fname. where Activity_flag = 'Y';
Quit;

%if &amp;amp;sqlobs. = 0
%then %do;
proc delete data=
  &amp;amp;fname.
  &amp;amp;fname._test
;
run;
%end;

%mend;

%import_text(A_Sample)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can now call this macro repeatedly from a dataset or from a text file with CALL EXECUTE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set datasets;
call execute('%nrstr(%import_text('!!trim(fname)!!'))');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 May 2021 13:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-for-txt-file-with-no-header-and-Datasets-for-each-file/m-p/740459#M29066</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-11T13:18:09Z</dc:date>
    </item>
  </channel>
</rss>

