<?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: How to define a format for a character value differentiating by its length? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435054#M108033</link>
    <description>&lt;P&gt;This also works, thank you&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 20:50:11 GMT</pubDate>
    <dc:creator>tjsari</dc:creator>
    <dc:date>2018-02-07T20:50:11Z</dc:date>
    <item>
      <title>How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435022#M108019</link>
      <description>&lt;P&gt;I have a character field with length 3 in a data set. Some sample values are: 001, 234, 546,1, 25, 025.&lt;/P&gt;&lt;P&gt;I am using tabulate to identify valid and invalid values in that field. The problem is that this code is not differentiating between the value 001 and 1 or between 25 and 025.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;value $code&amp;nbsp;(notsorted)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;" " = "blank"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"000"-"999" = "3 digits";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc tabulate data=dataset1 missing;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;format code $code.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;class code / preloadformat;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;table code, n / printmiss;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 19:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435022#M108019</guid>
      <dc:creator>tjsari</dc:creator>
      <dc:date>2018-02-07T19:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435028#M108022</link>
      <description>&lt;P&gt;Sounds like you have accidentally loaded the values into a numeric variable instead of a character variable.&lt;/P&gt;
&lt;P&gt;Can you re-read the source data?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 19:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435028#M108022</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-07T19:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435030#M108023</link>
      <description>&lt;P&gt;The variable "code" is character length 3&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 19:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435030#M108023</guid>
      <dc:creator>tjsari</dc:creator>
      <dc:date>2018-02-07T19:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435040#M108028</link>
      <description>&lt;P&gt;Before you go too far down this path, you should be aware of a pitfall.&amp;nbsp; As character strings, the range "000" - "999" includes many values that are not three digits.&amp;nbsp; All of these values are included in that range:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5 4&lt;/P&gt;
&lt;P&gt;3AD&lt;/P&gt;
&lt;P&gt;68&lt;/P&gt;
&lt;P&gt;1234 (perhaps not applicable, if your variable is defined as character length 3)&lt;/P&gt;
&lt;P&gt;3.1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to rethink the plan here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435040#M108028</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T20:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435043#M108029</link>
      <description>&lt;P&gt;Yes, that is the problem. Is there another way to identify the observations that have 3 digits and those who do not have 3 digits?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435043#M108029</guid>
      <dc:creator>tjsari</dc:creator>
      <dc:date>2018-02-07T20:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435047#M108030</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56209"&gt;@tjsari&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The variable "code" is character length 3&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Length is a property, formats work on values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately when doing character comparisons '1' is greater than '000' because in the character by character comparison the 1 as the first character is greater than the 0 of 000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would have to list all of the values to apply the format two and not use a range: '000', '001', '002' ... '999'. Not impossible&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data work.cntl;
   fmtname='Code';
   type='C';
   length label $ 10 start $ 3;
   start=''; label='blank';output;
   do i= 0 to 9;
      label='1 digit';
      start= put(i,z1.);
      output;
   end;
   do i= 0 to 99;
      label='2 digits';
      start= put(i,z2.);
      output;
   end;
   do i= 0 to 999;
      label='3 digits';
      start= put(i,z3.);
      output;
   end;
run;

proc format library=work cntlin=work.cntl;
run;

data junk;
   length x $ 3;
   x=''; put x $code.;
   x='1'; put x $code.;
   x='01';put x $code.;
   x='101';put x $code.;
   x='001';put x $code.;
run;&lt;/PRE&gt;
&lt;P&gt;If you have ' 1' values, with an actual leading space then the above code will need something to create values with leading spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435047#M108030</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-07T20:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435051#M108031</link>
      <description>&lt;P&gt;In a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if length(var) = 3 and (100 &amp;lt;= input(var, ??3.) &amp;lt;= 999);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A WHERE statement becomes tricky since it does not permit the "??" to suppress messages about invalid data.&amp;nbsp; It generates a warning when you remove the "??" but WHERE is legal in a PROC step if you can live with the warning.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435051#M108031</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-07T20:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435052#M108032</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435052#M108032</guid>
      <dc:creator>tjsari</dc:creator>
      <dc:date>2018-02-07T20:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a format for a character value differentiating by its length?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435054#M108033</link>
      <description>&lt;P&gt;This also works, thank you&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-define-a-format-for-a-character-value-differentiating-by/m-p/435054#M108033</guid>
      <dc:creator>tjsari</dc:creator>
      <dc:date>2018-02-07T20:50:11Z</dc:date>
    </item>
  </channel>
</rss>

