<?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: reading records from a file into macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478945#M123564</link>
    <description>&lt;P&gt;Macro processing happens before your code is compiled and executed. So it is not suitable for what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a look at &lt;A href="https://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0urpv7yyzylqsn1g2fycva2bs3n.htm&amp;amp;locale=en" target="_self"&gt;Proc FCMP&lt;/A&gt;, this allows you to write your own functions to be used in the DATA Step.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 07:51:19 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2018-07-18T07:51:19Z</dc:date>
    <item>
      <title>reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478867#M123524</link>
      <description>&lt;P&gt;I have a macro that takes two values (both are text): pattern and serial.&lt;BR /&gt;I have&amp;nbsp;a data set&amp;nbsp;with these two variables (i.e. patterns).&lt;BR /&gt;How would I go about reading in, for example, the first 20 rows, then the next 20 rows, etc.&lt;BR /&gt;Each time a group of records is inputted the results would be stored or outputted where check equals 1 or 2.&lt;/P&gt;&lt;P&gt;The data that I am applying this macro to is in a separate data set (i.e. all_data).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prx(pattern,serial);&lt;BR /&gt;b=prxparse("&amp;amp;pattern");&lt;BR /&gt;if prxmatch(b,serial_number)&amp;gt;0 then do;&lt;BR /&gt;check=1;&lt;BR /&gt;serial=&amp;amp;serial;&lt;BR /&gt;if (length(serial) = length(serial_number)) then check=2;&lt;BR /&gt;end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example values and how they would fit into the macro:&lt;BR /&gt;pattern=066957&lt;BR /&gt;serial=0669578&lt;BR /&gt;%prx(/^066957[\d{1}]/,"0669578");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of the records&amp;nbsp;that I would like to feed into the macro&amp;nbsp;(only 2 columns):&lt;BR /&gt;Serial&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pattern&lt;BR /&gt;B266056&amp;nbsp; &amp;nbsp;B26605&lt;BR /&gt;00308110&amp;nbsp; 0030811&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 23:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478867#M123524</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2018-07-17T23:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478874#M123529</link>
      <description>&lt;P&gt;1. Why read groups of 20 records? Please clarify this point.&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;Any good reason to use a RegEx instead if the index function? It's a lot slower.&lt;/P&gt;
&lt;P&gt;3. Variable SERIAL_NUMBER is used but never defined.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 00:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478874#M123529</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-18T00:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478880#M123530</link>
      <description>&lt;P&gt;1) 20 is just an example. The data set I'm searching for specific patterns has over 700,000 serial numbers. So, I want to run the macro for about 20-30 patterns at a time.&lt;/P&gt;&lt;P&gt;2) The total number of patterns I'm searching for is about 1,000. In addition to the example I provided, I have some other regular expressions that I'm interested in as well&lt;SPAN&gt;.&amp;nbsp;&lt;/SPAN&gt;Maybe I'm mistaken, but&amp;nbsp;&lt;SPAN&gt;RegEx&amp;nbsp;is better at finding specific patterns than the index function? What I'm currently interested in is finding out is how to pipe a list of values through a macro and capture the results.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3) I'm using the macro to find various patterns within&amp;nbsp;SERIAL_NUMBER. The&amp;nbsp;SERIAL_NUMBER variable is found in the data set with over 700,000 records.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 01:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478880#M123530</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2018-07-18T01:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478883#M123533</link>
      <description>&lt;P&gt;This is still not very clear.&lt;/P&gt;
&lt;P&gt;Here is a canvas. What's missing?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro prx(pattern,serial);
  PRX=prxparse("&amp;amp;pattern");
  if prxmatch(PRX,SERIAL_NUMBER)&amp;gt;0 then do;
    CHECK=1;
    if length("&amp;amp;serial") = length(serial_number) then CHECK=2;
  end;
%mend;

data HAVE;
  PATTERN='066957 ';  SERIAL_NUMBER ='0669578 ';  output;
  PATTERN='B26605 ';  SERIAL_NUMBER ='B266056 ';  output;
  PATTERN='0030811';  SERIAL_NUMBER ='00308110';  output;
run;

data WANT;
  set HAVE;
  %prx(/^066957\d/, 0669578);
  drop PRX;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 01:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478883#M123533</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-18T01:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478926#M123553</link>
      <description>&lt;P&gt;asset_data has serial_number (see below).&lt;BR /&gt;There are over 700,000 records in asset_data.&lt;BR /&gt;I'm interested in the records where check equals 1 or 2.&lt;BR /&gt;My goal is to avoid calling %prx over and over again.&lt;BR /&gt;So, instead of calling %prx repeatedly how can I have %prx automatically take pattern and serial from patterns_data (see below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data patterns_data;&lt;BR /&gt;PATTERN='066957 '; serial ='0669578 '; output;&lt;BR /&gt;PATTERN='B26605 '; serial ='B266056 '; output;&lt;BR /&gt;PATTERN='0030811'; serial ='00308110'; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prx(pattern,serial);&lt;BR /&gt;b=prxparse("&amp;amp;pattern");&lt;BR /&gt;if prxmatch(b,serial_number)&amp;gt;0 then do;&lt;BR /&gt;check=1;&lt;BR /&gt;serial=&amp;amp;serial;&lt;BR /&gt;if (length(serial) = length(serial_number)) then check=2;&lt;BR /&gt;end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WANT;&lt;BR /&gt;set asset_data;&lt;/P&gt;&lt;P&gt;%prx(/^&lt;SPAN&gt;066957&lt;/SPAN&gt;[\d{1}]/,"&lt;SPAN&gt;0669578&lt;/SPAN&gt;");&lt;BR /&gt;%prx(/^&lt;SPAN&gt;B26605&lt;/SPAN&gt;[\d{1}]/,"&lt;SPAN&gt;B266056&lt;/SPAN&gt;");&lt;/P&gt;&lt;P&gt;/*etc.*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 05:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478926#M123553</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2018-07-18T05:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478933#M123557</link>
      <description>&lt;P&gt;Come on. This doesn;t make sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your RegEx in&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data WANT;&lt;BR /&gt;set asset_data;&lt;/P&gt;
&lt;P&gt;%prx(/^&lt;SPAN&gt;066957&lt;/SPAN&gt;[\d{1}]/,"&lt;SPAN&gt;0669578&lt;/SPAN&gt;");&lt;BR /&gt;%prx(/^&lt;SPAN&gt;B26605&lt;/SPAN&gt;[\d{1}]/,"&lt;SPAN&gt;B266056&lt;/SPAN&gt;");&lt;/P&gt;
&lt;P&gt;/*etc.*/&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is static.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result will be the same&amp;nbsp;for all records in&amp;nbsp;&lt;SPAN&gt;asset_data as the records are not used.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 07:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478933#M123557</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-18T07:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478945#M123564</link>
      <description>&lt;P&gt;Macro processing happens before your code is compiled and executed. So it is not suitable for what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a look at &lt;A href="https://go.documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p0urpv7yyzylqsn1g2fycva2bs3n.htm&amp;amp;locale=en" target="_self"&gt;Proc FCMP&lt;/A&gt;, this allows you to write your own functions to be used in the DATA Step.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 07:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/478945#M123564</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-07-18T07:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/479209#M123653</link>
      <description>&lt;P&gt;OK, this sounds promising.&lt;/P&gt;&lt;P&gt;So, how would I get two variables (i.e. "pattern" and "serial") from&amp;nbsp;&lt;SPAN&gt;patterns_data in order to look for patterns in serial_number (which is located in&amp;nbsp;asset_data)?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;b=prxparse(/^pattern[\d{1}]/);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if prxmatch(b,serial_number)&amp;gt;0 then do;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;check=1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (length(serial) = length(serial_number)) then check=2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 19:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/479209#M123653</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2018-07-18T19:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/479362#M123717</link>
      <description>&lt;P&gt;This is one messy post.&lt;/P&gt;
&lt;P&gt;So you want to generate matching code from the smaller pattern table it seems.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If only you gave proper data in/ data out examples.&lt;/P&gt;
&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PATTERNS;
  PATTERN='066957 '; SERIAL ='0669578 '; output;
  PATTERN='B26605 '; SERIAL ='B26056 '; output;
  PATTERN='0030811'; SERIAL ='00308110'; output;
run;

data HAVE;
  SERIAL_NUMBER ='0669578 '; output;
  SERIAL_NUMBER ='B266056 '; output;  
  SERIAL_NUMBER ='0038110'; output;
run;

data _null_;
  retain CODE;
  length CODE $32000;
  set PATTERNS;
  CODE=cats( CODE
           , 'if prxmatch("/^', PATTERN, '\d{1}/", SERIAL_NUMBER)&amp;gt;0 then do;'
           , '  CHECK=1; '
           , '  if (', length(SERIAL), ' = length(SERIAL_NUMBER)) then CHECK=2; '
           , 'end;'
           );
  call symputx('code',CODE);
run;
 
data WANT;
  set HAVE;
  &amp;amp;code.;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="174"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="110"&gt;SERIAL_NUMBER&lt;/TD&gt;
&lt;TD width="64"&gt;CHECK&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;669578&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;B266056&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;38110&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 02:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/479362#M123717</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-19T02:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: reading records from a file into macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/479375#M123726</link>
      <description>&lt;P&gt;Don't pipe data through macros. Use datasets to hold data.&lt;/P&gt;
&lt;P&gt;You could make a macro that you tell it WHICH records you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro process
(pattern_dsn=  /* Name of Pattern dataset */
,records_dsn= /* Name of Data to Test */
,out_dsn=  /* Name of dataset to create */
,first_obs=  /* First pattern number */
,n_obs=  /* Number of patterns */
);

data subset ;
  set &amp;amp;pattern_dsn (firstobs=&amp;amp;first_obs obs=&amp;amp;n_obs);
run;
 
....
%mend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As to the process of building Reg Ex strings from the patterns do that with DATA step code and NOT with macro code.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 04:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-records-from-a-file-into-macro/m-p/479375#M123726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-19T04:47:53Z</dc:date>
    </item>
  </channel>
</rss>

