<?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 Proc Format Invalue regex hierarchy in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873547#M345161</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to use proc format with regex so that it sequentially evaluates conditions in the order given?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc format;
	invalue $Fr
	"s/(.*)(PELICA|UNDEREDS|GRASSHOP)(.*)/PELICA/i"	(regexpe) = _same_
	"s/(.*)(DEATHS|DT|CID)(.*)/DEATHS/i"	(regexpe) = _same_
	"s/(.*)(GRA)(.*)/LLL/i"	(regexpe) = _same_
	"s/(.*)(EMPRE)(.*)/EMPRESSS/i"	(regexpe) = _same_
	other = ''
	;
quit;
data fruit;
	length fruit $50. ;
	infile cards dsd dlm='&amp;gt;' truncover;
	input fruit ;
	cards;
	DEATHS
	PELICA
	PRIZEDE UNDEREDS/EMPRESSS
	GRASSHOP
	GRAMS
run;
data fruit2;
	set fruit;
	fruitset=input(fruit,$Fr.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sc5_0-1683097816287.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83516i5A9D2E78AD01E6FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sc5_0-1683097816287.png" alt="sc5_0-1683097816287.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But I want the output to be:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sc5_1-1683097905691.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83517i81F138A8DF5F40AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sc5_1-1683097905691.png" alt="sc5_1-1683097905691.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;i.e. I want the conditions in proc format to be evaluated in the order given. The 3rd row matches the 1st regex condition (the word '&lt;CODE class=""&gt;UNDEREDS')&lt;/CODE&gt;, so the output should be PELICA, not EMPRESSS. I only want the output to be EMPRESSS if the conditions before are not met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how I can achieve this? Or is there another way I can format strings based on patterns in a specific order of preference? Worst case I'll resort to if-then conditions, but I have a lot of columns to parse with a lot of conditions, and a huge dataset, so I'm trying to do it in a more modular/elegant way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 May 2023 07:21:08 GMT</pubDate>
    <dc:creator>sc5</dc:creator>
    <dc:date>2023-05-03T07:21:08Z</dc:date>
    <item>
      <title>Proc Format Invalue regex hierarchy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873547#M345161</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to use proc format with regex so that it sequentially evaluates conditions in the order given?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc format;
	invalue $Fr
	"s/(.*)(PELICA|UNDEREDS|GRASSHOP)(.*)/PELICA/i"	(regexpe) = _same_
	"s/(.*)(DEATHS|DT|CID)(.*)/DEATHS/i"	(regexpe) = _same_
	"s/(.*)(GRA)(.*)/LLL/i"	(regexpe) = _same_
	"s/(.*)(EMPRE)(.*)/EMPRESSS/i"	(regexpe) = _same_
	other = ''
	;
quit;
data fruit;
	length fruit $50. ;
	infile cards dsd dlm='&amp;gt;' truncover;
	input fruit ;
	cards;
	DEATHS
	PELICA
	PRIZEDE UNDEREDS/EMPRESSS
	GRASSHOP
	GRAMS
run;
data fruit2;
	set fruit;
	fruitset=input(fruit,$Fr.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sc5_0-1683097816287.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83516i5A9D2E78AD01E6FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sc5_0-1683097816287.png" alt="sc5_0-1683097816287.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But I want the output to be:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sc5_1-1683097905691.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83517i81F138A8DF5F40AA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sc5_1-1683097905691.png" alt="sc5_1-1683097905691.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;i.e. I want the conditions in proc format to be evaluated in the order given. The 3rd row matches the 1st regex condition (the word '&lt;CODE class=""&gt;UNDEREDS')&lt;/CODE&gt;, so the output should be PELICA, not EMPRESSS. I only want the output to be EMPRESSS if the conditions before are not met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how I can achieve this? Or is there another way I can format strings based on patterns in a specific order of preference? Worst case I'll resort to if-then conditions, but I have a lot of columns to parse with a lot of conditions, and a huge dataset, so I'm trying to do it in a more modular/elegant way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 07:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873547#M345161</guid>
      <dc:creator>sc5</dc:creator>
      <dc:date>2023-05-03T07:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Invalue regex hierarchy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873555#M345164</link>
      <description>&lt;P&gt;See if this helps:&lt;/P&gt;
&lt;PRE&gt;proc format;
	invalue $Fr  &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;(notsorted)&lt;/STRONG&gt;&lt;/FONT&gt;
	"s/(.*)(PELICA|UNDEREDS|GRASSHOP)(.*)/PELICA/i"	(regexpe) = _same_
	"s/(.*)(DEATHS|DT|CID)(.*)/DEATHS/i"	(regexpe) = _same_
	"s/(.*)(GRA)(.*)/LLL/i"	(regexpe) = _same_
	"s/(.*)(EMPRE)(.*)/EMPRESSS/i"	(regexpe) = _same_
	other = ''
	;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 May 2023 07:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873555#M345164</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-03T07:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Invalue regex hierarchy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873556#M345165</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;absolutely. You could also define your formats as a chain with the keyword 'other' to control in detail what happens:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
	invalue $Fr1_ "s/(.*)(PELICA|UNDEREDS|GRASSHOP)(.*)/PELICA/i"	(regexpe) = _same_ other=[$Fr2_.];
	invalue $Fr2_ "s/(.*)(DEATHS|DT|CID)(.*)/DEATHS/i"	(regexpe) = _same_ other=[$Fr3_.];
	invalue $Fr3_ "s/(.*)(GRA)(.*)/LLL/i"	(regexpe) = _same_ other=[$Fr4_.];
	invalue $Fr4_ "s/(.*)(EMPRE)(.*)/EMPRESSS/i"	(regexpe) = _same_ other=' ';
	;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 07:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873556#M345165</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-03T07:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Invalue regex hierarchy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873558#M345166</link>
      <description>This seems to work, thanks a lot!</description>
      <pubDate>Wed, 03 May 2023 07:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873558#M345166</guid>
      <dc:creator>sc5</dc:creator>
      <dc:date>2023-05-03T07:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Format Invalue regex hierarchy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873559#M345167</link>
      <description>Ooh ok I didn't know we could do that, thank you!</description>
      <pubDate>Wed, 03 May 2023 07:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Format-Invalue-regex-hierarchy/m-p/873559#M345167</guid>
      <dc:creator>sc5</dc:creator>
      <dc:date>2023-05-03T07:57:37Z</dc:date>
    </item>
  </channel>
</rss>

