<?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 Regular expression, loop, and macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-loop-and-macro-variable/m-p/621347#M182660</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Starting from this subject:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-create-columns-with-values-based-on-occurence-of-words/td-p/595563/highlight/true" target="_self"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-create-columns-with-values-based-on-occurence-of-words/td-p/595563/highlight/true,&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I wanted to solve it with regular expressions (just a challenge for me).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Passing parametres seems to me not to work.&lt;/P&gt;&lt;P&gt;Could you help me.&lt;/P&gt;&lt;P&gt;Thank you:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variables;                                                                                                                         
   infile datalines delimiter=',' dsd;                                                                                                  
   length cars $6 vegetables $12 regions $14;                                                                                           
   input cars $ vegetables $ regions $;                                                                                                 
   datalines;                                                                                                                           
Audi,beans,America                                                                                                                      
BMW,black beans,Central Europe                                                                                                          
BMW X5,carrot,East Europe                                                                                                               
X5,chili pepper,Europe                                                                                                                  
Honda,green beans,North America                                                                                                         
,lettuce,South America                                                                                                                  
,onion,                                                                                                                                 
,pepper,                                                                                                                                
;                                                                                                                                       
run;                                                                                                                                    


data test ;                                                                                                                          
  input var $30.;                                                                                                                    
  cards ;                                                                                                                               
Ford carrot                                                                                                                             
Honda beans                                                                                                                             
south america black beans                                                                                                               
green beans Audi                                                                                                                        
x5 chili pepper lettuce                                                                                                                 
garlic north America                                                                                                                    
central europe bmw                                                                                                                      
lettuce onion X5                                                                                                                        
America pepper                                                                                                                          
X5 BMW Europe                                                                                                                           
Central East Europe                                                                                                                     
bmw X5 america                                                                                                                          
;                                                                                                                                       
run ;  

                                                                                                                                 
                                                                                                                                        
proc sql; 
select distinct cars , length(cars) as maxcar into: cars separated by '|'  
from variables where cars ne "" order by   maxcar desc;

select distinct vegetables , length(vegetables) as maxvege into: vege separated by '|'  
from variables where vegetables ne "" order by   maxvege desc;

select distinct regions , length(regions) as maxregion into: region separated by '|'  
from variables where regions ne "" order by   maxregion desc;

%put &amp;amp;cars;
%put &amp;amp;vege;
%put &amp;amp;region;
        
option mlogic mprint ; 

%macro tt(); 
data test1 (drop=patt: START LENGTH);
set test;

 %let PATTERN1 =  %sysfunc(PRXPARSE("/&amp;amp;cars/i"));
  %let PATTERN2 =  %sysfunc(PRXPARSE("&amp;amp;vege/i"));
   %let PATTERN3 =  %sysfunc(PRXPARSE("/&amp;amp;region/i"));
  
length var1 $8;

%do i=1 %to 3;
 %syscall PRXSUBSTR (&amp;amp;&amp;amp;PATTERN&amp;amp;i,var,START,LENGTH));
    %IF START GT 0 %THEN %DO;
    var&amp;amp;i = SUBSTR(var,START,LENGTH);
    %end;
  %else %do;
     var&amp;amp;i="";
  %end;
 %end;
 output;
run;
%mend tt;
%tt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 31 Jan 2020 00:25:05 GMT</pubDate>
    <dc:creator>mansour_ib_sas</dc:creator>
    <dc:date>2020-01-31T00:25:05Z</dc:date>
    <item>
      <title>Regular expression, loop, and macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-loop-and-macro-variable/m-p/621347#M182660</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Starting from this subject:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-create-columns-with-values-based-on-occurence-of-words/td-p/595563/highlight/true" target="_self"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-create-columns-with-values-based-on-occurence-of-words/td-p/595563/highlight/true,&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I wanted to solve it with regular expressions (just a challenge for me).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Passing parametres seems to me not to work.&lt;/P&gt;&lt;P&gt;Could you help me.&lt;/P&gt;&lt;P&gt;Thank you:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data variables;                                                                                                                         
   infile datalines delimiter=',' dsd;                                                                                                  
   length cars $6 vegetables $12 regions $14;                                                                                           
   input cars $ vegetables $ regions $;                                                                                                 
   datalines;                                                                                                                           
Audi,beans,America                                                                                                                      
BMW,black beans,Central Europe                                                                                                          
BMW X5,carrot,East Europe                                                                                                               
X5,chili pepper,Europe                                                                                                                  
Honda,green beans,North America                                                                                                         
,lettuce,South America                                                                                                                  
,onion,                                                                                                                                 
,pepper,                                                                                                                                
;                                                                                                                                       
run;                                                                                                                                    


data test ;                                                                                                                          
  input var $30.;                                                                                                                    
  cards ;                                                                                                                               
Ford carrot                                                                                                                             
Honda beans                                                                                                                             
south america black beans                                                                                                               
green beans Audi                                                                                                                        
x5 chili pepper lettuce                                                                                                                 
garlic north America                                                                                                                    
central europe bmw                                                                                                                      
lettuce onion X5                                                                                                                        
America pepper                                                                                                                          
X5 BMW Europe                                                                                                                           
Central East Europe                                                                                                                     
bmw X5 america                                                                                                                          
;                                                                                                                                       
run ;  

                                                                                                                                 
                                                                                                                                        
proc sql; 
select distinct cars , length(cars) as maxcar into: cars separated by '|'  
from variables where cars ne "" order by   maxcar desc;

select distinct vegetables , length(vegetables) as maxvege into: vege separated by '|'  
from variables where vegetables ne "" order by   maxvege desc;

select distinct regions , length(regions) as maxregion into: region separated by '|'  
from variables where regions ne "" order by   maxregion desc;

%put &amp;amp;cars;
%put &amp;amp;vege;
%put &amp;amp;region;
        
option mlogic mprint ; 

%macro tt(); 
data test1 (drop=patt: START LENGTH);
set test;

 %let PATTERN1 =  %sysfunc(PRXPARSE("/&amp;amp;cars/i"));
  %let PATTERN2 =  %sysfunc(PRXPARSE("&amp;amp;vege/i"));
   %let PATTERN3 =  %sysfunc(PRXPARSE("/&amp;amp;region/i"));
  
length var1 $8;

%do i=1 %to 3;
 %syscall PRXSUBSTR (&amp;amp;&amp;amp;PATTERN&amp;amp;i,var,START,LENGTH));
    %IF START GT 0 %THEN %DO;
    var&amp;amp;i = SUBSTR(var,START,LENGTH);
    %end;
  %else %do;
     var&amp;amp;i="";
  %end;
 %end;
 output;
run;
%mend tt;
%tt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Jan 2020 00:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-loop-and-macro-variable/m-p/621347#M182660</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2020-01-31T00:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Regular expression, loop, and macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Regular-expression-loop-and-macro-variable/m-p/621351#M182661</link>
      <description>&lt;P&gt;You don't seem to understand the difference between macro code and SAS code. In particular this statement makes no sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF START GT 0 %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A five character string that starts with the letter S is always going come after the digit 0 in the lexical ordering used for character strings.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 01:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Regular-expression-loop-and-macro-variable/m-p/621351#M182661</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-31T01:06:28Z</dc:date>
    </item>
  </channel>
</rss>

