<?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 Format based on a digit in numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684426#M207401</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just wondering if it is possible to format a numeric based on values of specific digits in a PROC FORMAT?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, would it be possible to format these numbers based on the coloured digits only &lt;EM&gt;without a data step to split them out first&lt;/EM&gt;? (for example, the thousands values, irrespective of what the other values are... is there a wildcard type approach?)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;50&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;12&lt;/STRONG&gt;&lt;/FONT&gt;10&lt;/P&gt;&lt;P&gt;70&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;13&lt;/STRONG&gt;&lt;/FONT&gt;04&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm aware how to do this in a data step but, having just concatenated the variables for efficiency, I don't want to split them back out for formatting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;EDIT: Adding context that I should have included in the first place!&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;The format of the variable could be either numeric or character - either works for my purposes, by character is easier. The use of the format would for grouping in a class in a PROC TABULATE. Definitely not in a PUT statement as I don't want to split the data back out.&lt;BR /&gt;&lt;BR /&gt;For further context ... as an example, if my data has many variables in one row like: &lt;EM&gt;Value_at_8am [2 digits]&lt;/EM&gt;, &lt;EM&gt;Value_at_9am [2 digits]&lt;/EM&gt;, &lt;EM&gt;Value_at_10am [2 digits]&lt;/EM&gt; ... and I concatenate them, can I then have a format that classifies based on the &lt;EM&gt;Value_at_9am&amp;nbsp;&lt;/EM&gt;&lt;STRONG&gt;in the new concatenated string&lt;/STRONG&gt; irrespective of the value that come before or after it in the concatenated string?&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;So, Ideally, I have a concatenated string when any range 01-99 in the 3rd and 4th places could be formatted to "True":&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Proc Format&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;Value wishful&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&amp;nbsp;**01** - **99** = "Value at 9am is True"&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;**00** = "Value at 9am is False"&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;****01-****99 = "Value at 10 am is True"&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;... etc.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cheers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Sep 2020 00:29:12 GMT</pubDate>
    <dc:creator>ProtoLithic</dc:creator>
    <dc:date>2020-09-17T00:29:12Z</dc:date>
    <item>
      <title>Format based on a digit in numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684426#M207401</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just wondering if it is possible to format a numeric based on values of specific digits in a PROC FORMAT?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, would it be possible to format these numbers based on the coloured digits only &lt;EM&gt;without a data step to split them out first&lt;/EM&gt;? (for example, the thousands values, irrespective of what the other values are... is there a wildcard type approach?)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;50&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;12&lt;/STRONG&gt;&lt;/FONT&gt;10&lt;/P&gt;&lt;P&gt;70&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;13&lt;/STRONG&gt;&lt;/FONT&gt;04&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm aware how to do this in a data step but, having just concatenated the variables for efficiency, I don't want to split them back out for formatting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;EDIT: Adding context that I should have included in the first place!&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;The format of the variable could be either numeric or character - either works for my purposes, by character is easier. The use of the format would for grouping in a class in a PROC TABULATE. Definitely not in a PUT statement as I don't want to split the data back out.&lt;BR /&gt;&lt;BR /&gt;For further context ... as an example, if my data has many variables in one row like: &lt;EM&gt;Value_at_8am [2 digits]&lt;/EM&gt;, &lt;EM&gt;Value_at_9am [2 digits]&lt;/EM&gt;, &lt;EM&gt;Value_at_10am [2 digits]&lt;/EM&gt; ... and I concatenate them, can I then have a format that classifies based on the &lt;EM&gt;Value_at_9am&amp;nbsp;&lt;/EM&gt;&lt;STRONG&gt;in the new concatenated string&lt;/STRONG&gt; irrespective of the value that come before or after it in the concatenated string?&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;So, Ideally, I have a concatenated string when any range 01-99 in the 3rd and 4th places could be formatted to "True":&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Proc Format&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;Value wishful&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&amp;nbsp;**01** - **99** = "Value at 9am is True"&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;**00** = "Value at 9am is False"&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;****01-****99 = "Value at 10 am is True"&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;... etc.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cheers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 00:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684426#M207401</guid>
      <dc:creator>ProtoLithic</dc:creator>
      <dc:date>2020-09-17T00:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Format based on a digit in numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684430#M207402</link>
      <description>&lt;P&gt;What type variable/format are you looking for here. Numeric or Character?&amp;nbsp; Is your variable numeric or character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain what values you want be displayed by the format?&amp;nbsp; For example show what displayed value you want for the stored values you showed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you going to use this format?&amp;nbsp; Just for printing the output? For grouping , like in a CLASS variable? For making a new variable with the PUT() function?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 00:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684430#M207402</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-17T00:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Format based on a digit in numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684431#M207403</link>
      <description>&lt;P&gt;There may be other ways, but I know PROC FCMP will get your there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA raw;
  INFILE DATALINES;
  INPUT myval $6.;
DATALINES;
501210
701304
;
run;


proc fcmp outlib=work.functions.fun; 
   function mask(string $) $;
      return (substr(string,3,2));
   endsub;
run;

options cmplib=work.functions;
proc format;
    value $ mask (default=200) other=[mask()];
    value $ masky '11' = 'Eleven' 
                  '12' = 'Twelve'
                  '13' = 'Thirteen';
run;

data results;
  set raw;
  formated = put(put(myval,$mask.),$masky.);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 00:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684431#M207403</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-17T00:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Format based on a digit in numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684438#M207407</link>
      <description>&lt;P&gt;I realized you wanted a numeric format.&amp;nbsp; Its a simple fix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA raw;
  INFILE DATALINES;
  INPUT myval 8.;
DATALINES;
501210
701304
;
run;


proc fcmp outlib=work.functions.fun; 
   function mask(num_in) $;
      return (substr(put(num_in,Z6.),3,2));
   endsub;
run;

options cmplib=work.functions;
proc format;
    value  mask (default=200) other=[mask()];
    value $ masky '11' = 'Eleven' 
                  '12' = 'Twelve'
                  '13' = 'Thirteen';
 
run;

data results;
  set raw;
  formated = put(put(myval,mask.),$masky.);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 00:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684438#M207407</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-17T00:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Format based on a digit in numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684445#M207411</link>
      <description>&lt;P&gt;I might just be easiest to make your format from your data.&amp;nbsp; So if your data looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string $10. @1 number ;
cards;
501210
701304
600055
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could convert numeric variable NUMBER to the middle two digits by a formula like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  want1 = int(mod(number,10**4)/10**2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So use that to make a CNTLIN dataset to define your name format. Let's call it V9AM.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table cntlin as
  select distinct
         'V9AM' as fmtname 
       , number as start
       , int(mod(number,10**4)/10**2) as v9AM
       , case when (calculated v9am = 0) then 'Value at 9am is False' else 'Value at 9am is True' end as label
  from have 
  order by 1,2
;
quit;
proc format cntlin=cntlin; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that format in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=have ;
   format number v9am. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    string           number

 1     501210    Value at 9am is True
 2     701304    Value at 9am is True
 3     600055    Value at 9am is False

&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 00:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684445#M207411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-17T00:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Format based on a digit in numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684448#M207414</link>
      <description>This is genius, thanks. But will is run into issues if the dataset is large (many combinations)? Will the format be too cumbersome?</description>
      <pubDate>Thu, 17 Sep 2020 01:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-based-on-a-digit-in-numeric/m-p/684448#M207414</guid>
      <dc:creator>ProtoLithic</dc:creator>
      <dc:date>2020-09-17T01:10:47Z</dc:date>
    </item>
  </channel>
</rss>

