<?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: Convert text string to lower case - Except for text in quotes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866943#M342391</link>
    <description>&lt;P&gt;Here is a program that does what you want, more or less:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  set have;                                                                                                                             
  prx_squote=prxparse('/''[^'']*''/');                                                                                                  
  prx_dquote=prxparse('/"[^"]*"/');                                                                                                     
  pos_squote=1;                                                                                                                         
  pos_dquote=1;                                                                                                                         
  pos=1;                                                                                                                                
  pos1=1;                                                                                                                               
  pos2=1;                                                                                                                               
  len_squote=0;                                                                                                                         
  len_dquote=0;                                                                                                                         
  call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                                      
  call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                                      
  if pos_squote=0 and pos_dquote=0 then                                                                                                 
    fullline=lowcase(fullline);                                                                                                         
  else do while(pos_squote or pos_dquote);                                                                                              
    if pos_squote and pos_dquote then do;                                                                                               
      if pos_squote&amp;lt;pos_dquote then do;                                                                                                 
        substr(fullline,pos,pos_squote-pos)=lowcase(substr(fullline,pos,pos_squote-pos));                                               
        pos=pos1;                                                                                                                       
        if pos_dquote&amp;lt;pos then do;                                                                                                      
          pos2=pos;                                                                                                                     
          call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                              
          end;                                                                                                                          
        call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                                
        end;                                                                                                                            
      else do;                                                                                                                          
        substr(fullline,pos,pos_dquote-pos)=lowcase(substr(fullline,pos,pos_dquote-pos));                                               
        pos=pos2;                                                                                                                       
        if pos_squote&amp;lt;pos2 then do;                                                                                                     
          pos1=pos;                                                                                                                     
          call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                              
          end;                                                                                                                          
        call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                                
        end;                                                                                                                            
      end;                                                                                                                              
    else if pos_squote then do;                                                                                                         
      substr(fullline,pos,pos_squote-pos)=lowcase(substr(fullline,pos,pos_squote-pos));                                                 
      pos=pos1;                                                                                                                         
      call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                                  
      end;                                                                                                                              
    else do;                                                                                                                            
      substr(fullline,pos,pos_dquote-pos)=lowcase(substr(fullline,pos,pos_dquote-pos));                                                 
      pos=pos2;                                                                                                                         
      call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                                  
      end;                                                                                                                              
    end;                                                                                                                                
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is a bit complicated, because we have to account for quoted quotes (e.g. "Rob's Pizza Shop"), and it does not check for unmatched quotes - if your program looks like this, you will get both lines lower case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE a&amp;gt;'
GGG';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, it does not check for CARDS or DATALINES statements and macro quoted quotes (e.g. %STR(%')), and it will also put most comments in all lower case, so I would be a bit wary about just letting it loose on a large batch of programs.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2023 10:57:30 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-03-29T10:57:30Z</dc:date>
    <item>
      <title>Convert text string to lower case - Except for text in quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866910#M342383</link>
      <description>&lt;P&gt;Hi there SASsers,&lt;BR /&gt;I would like to know how I can programmatically input a string and change all text to lower case EXCEPT for text which is within quotation marks (single or double).&amp;nbsp; The quoted text should remain unchanged. I suspect this could be a job for Perl Regular Expressions (eg PRXCHANGE function).&lt;BR /&gt;&lt;BR /&gt;The background is : We have many (100+) very long (100-5000 lines) .sas programs. They have been written completely in Upper Case which makes it difficult to read easily. Many of the program statements refer to case sensitive values eg:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;/*Have*/&lt;/P&gt;&lt;P&gt;IF NAME='Rob' AND ADDRESS='21a High Street' THEN CHECKED="True";&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;/*Want*/&lt;/P&gt;&lt;P&gt;if name='Rob' and address='21a High Street' then checked="True";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can write some code to read in a .sas file and work on the text string, outputting to a new sas file with :&lt;/P&gt;&lt;P&gt;filename oldprog 'C:\temp\mySASprog.sas' ;&lt;BR /&gt;filename newprog 'C:\temp\mySASprogNEW.sas' ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;&amp;nbsp; file newprog ;&lt;BR /&gt;&amp;nbsp; infile oldprog missover lrecl=32767;&lt;BR /&gt;&amp;nbsp; informat fulline $300. ;&lt;BR /&gt;&amp;nbsp; input @1 fulline ;&lt;BR /&gt;&amp;nbsp; newline=lowcase(_infile_);&lt;BR /&gt;&amp;nbsp; put newLine;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However how do I get newline to convert to lower case and keep any quoted text untouched.&lt;BR /&gt;As I said earlier, sounds like a job for prxchange function or some combination of Perl / Regex functions?&lt;BR /&gt;Regards,&amp;nbsp; rob,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 04:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866910#M342383</guid>
      <dc:creator>robAs</dc:creator>
      <dc:date>2023-03-29T04:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text string to lower case - Except for text in quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866943#M342391</link>
      <description>&lt;P&gt;Here is a program that does what you want, more or less:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  set have;                                                                                                                             
  prx_squote=prxparse('/''[^'']*''/');                                                                                                  
  prx_dquote=prxparse('/"[^"]*"/');                                                                                                     
  pos_squote=1;                                                                                                                         
  pos_dquote=1;                                                                                                                         
  pos=1;                                                                                                                                
  pos1=1;                                                                                                                               
  pos2=1;                                                                                                                               
  len_squote=0;                                                                                                                         
  len_dquote=0;                                                                                                                         
  call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                                      
  call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                                      
  if pos_squote=0 and pos_dquote=0 then                                                                                                 
    fullline=lowcase(fullline);                                                                                                         
  else do while(pos_squote or pos_dquote);                                                                                              
    if pos_squote and pos_dquote then do;                                                                                               
      if pos_squote&amp;lt;pos_dquote then do;                                                                                                 
        substr(fullline,pos,pos_squote-pos)=lowcase(substr(fullline,pos,pos_squote-pos));                                               
        pos=pos1;                                                                                                                       
        if pos_dquote&amp;lt;pos then do;                                                                                                      
          pos2=pos;                                                                                                                     
          call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                              
          end;                                                                                                                          
        call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                                
        end;                                                                                                                            
      else do;                                                                                                                          
        substr(fullline,pos,pos_dquote-pos)=lowcase(substr(fullline,pos,pos_dquote-pos));                                               
        pos=pos2;                                                                                                                       
        if pos_squote&amp;lt;pos2 then do;                                                                                                     
          pos1=pos;                                                                                                                     
          call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                              
          end;                                                                                                                          
        call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                                
        end;                                                                                                                            
      end;                                                                                                                              
    else if pos_squote then do;                                                                                                         
      substr(fullline,pos,pos_squote-pos)=lowcase(substr(fullline,pos,pos_squote-pos));                                                 
      pos=pos1;                                                                                                                         
      call prxnext(prx_squote,pos1,-1,fullline,pos_squote,len_squote);                                                                  
      end;                                                                                                                              
    else do;                                                                                                                            
      substr(fullline,pos,pos_dquote-pos)=lowcase(substr(fullline,pos,pos_dquote-pos));                                                 
      pos=pos2;                                                                                                                         
      call prxnext(prx_dquote,pos2,-1,fullline,pos_dquote,len_dquote);                                                                  
      end;                                                                                                                              
    end;                                                                                                                                
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is a bit complicated, because we have to account for quoted quotes (e.g. "Rob's Pizza Shop"), and it does not check for unmatched quotes - if your program looks like this, you will get both lines lower case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE a&amp;gt;'
GGG';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, it does not check for CARDS or DATALINES statements and macro quoted quotes (e.g. %STR(%')), and it will also put most comments in all lower case, so I would be a bit wary about just letting it loose on a large batch of programs.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 10:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866943#M342391</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-29T10:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text string to lower case - Except for text in quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866948#M342393</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input have $80.;
cards4;
IF NAME='Rob' AND ADDRESS='21a High Street' THEN CHECKED="True";
IF NAME='Rob';
IF;
;;;;

data want;
set have;
length want $ 200;
  do i=1 to countw(have,"'""",'m') ;
    temp=scan(have,i,"'""",'m');
 if mod(i,2)=1 then temp=lowcase(temp);
   else temp=cats('"',temp,'"');
 want=catx(' ',want,temp);
  end;
  drop i temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Mar 2023 11:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-string-to-lower-case-Except-for-text-in-quotes/m-p/866948#M342393</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-29T11:47:58Z</dc:date>
    </item>
  </channel>
</rss>

