<?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: Why does proc format create duplicates? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594965#M171080</link>
    <description>&lt;P&gt;I've seen this format approach in if-statements but I never understood the benefit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be the reason to rather write:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value KBZ2range (FUZZ=0)
low-1 = "valid" 
1&amp;lt;-2 = "nv" 
2&amp;lt;-3 = "valid"
3&amp;lt;-4 = "nv"
4&amp;lt;-5 = "valid"
5&amp;lt;-high = "nv";
quit;

data foo;
set have;
if put(KBZ,KBZ2range.)='valid' then check='yes'; 
else check='no';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Instead of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo2;
set have;
if (KBZ&amp;lt;=1 or 2&amp;lt;KBZ&amp;lt;=3 or 4&amp;lt;KBZ&amp;lt;=5) then check='yes'; 
else check='no';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A lot of extra typing...&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2019 07:17:46 GMT</pubDate>
    <dc:creator>Emjay</dc:creator>
    <dc:date>2019-10-09T07:17:46Z</dc:date>
    <item>
      <title>Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594691#M170907</link>
      <description>&lt;P&gt;I want to use &lt;STRONG&gt;proc format &lt;/STRONG&gt;to transform my numerical variable into&amp;nbsp;a range variable. This works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I want to do some further analysis with this new range variable I have the problem that &lt;STRONG&gt;proc format&lt;/STRONG&gt; has created duplicates but I don't see why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So let's say I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input ID KBZ; 
datalines;
1 0.25
2 0.33
3 1.2
4 5.8
5 3.2
6 3.8
7 3.44
8 4.7
;
run;

proc format;
value KBZrange (FUZZ=0)
low-1 = "&amp;lt;=1" 
1&amp;lt;-2 = "1-2" 
2&amp;lt;-3 = "2-3"
3&amp;lt;-4 = "3-4"
4&amp;lt;-5 = "4-5"
5&amp;lt;-high = "&amp;gt;=5";
quit;

data have;
set have;
format KBZ_range KBZrange.;
KBZ_range=KBZ;
run;

proc sql;
create table why_dup as
select distinct KBZ_range from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Why are there now this extra rows although they look the same to me?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 10:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594691#M170907</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2019-10-08T10:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594692#M170908</link>
      <description>&lt;P&gt;I don't see any extra rows? Your initial data has 8 rows and so does why_dup?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 10:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594692#M170908</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-08T10:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594693#M170909</link>
      <description>&lt;P&gt;Yes it has 8 rows, but shouldn't it have only 5 as I wrote &lt;STRONG&gt;select distinct&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 11:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594693#M170909</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2019-10-08T11:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594696#M170916</link>
      <description>&lt;P&gt;No. PROC SQL considers the actual values of&amp;nbsp;KBZ_range. Not the formated values of&amp;nbsp;KBZ_range. Right now,&amp;nbsp;KBZ_range is exactly equal to&amp;nbsp;KBZ. They just look different because you gave it a different format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do like below however, then you give KBZ_range the values of the ranges you specify in PROC SORT (the actual strings), and you get 5 obs&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set have;
KBZ_range=put(KBZ, KBZrange.);
run;

proc sql;
create table why_dup as
select distinct KBZ_range from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;KBZ_Range
1-2
3-4
4-5
&amp;lt;=1
&amp;gt;=5&lt;/PRE&gt;
&lt;P&gt;Makes sense?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 11:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594696#M170916</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-08T11:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594699#M170918</link>
      <description>&lt;P&gt;Yes, makes sense. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I also understand why KBZ_range still had the type numeric and this blue circle next to it. I thought this was because sas didn't know how to display my custom format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 11:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594699#M170918</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2019-10-08T11:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594700#M170919</link>
      <description>&lt;P&gt;Spot on! SAS knows exactly how to display your custom format &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anytime, glad you found your answer.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 11:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594700#M170919</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-08T11:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594782#M170967</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202610"&gt;@Emjay&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, makes sense. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I also understand why KBZ_range still had the type numeric and this blue circle next to it. I thought this was because sas didn't know how to display my custom format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=have ;
   class kbz;
   format kbz kbzrange.;
   output out=work.summary  ;
run;&lt;/PRE&gt;
&lt;P&gt;You will find the groups created by the format are honored by other procedures, though you might be surprised sometimes what the actual value (unformatted)&amp;nbsp;kept with Proc Summary output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 15:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594782#M170967</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-08T15:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594784#M170969</link>
      <description>&lt;P&gt;You are right! And that's exactly why I was so confused. Cause I used my original approach with a &lt;STRONG&gt;proc freq &lt;/STRONG&gt;a while ago and there it also worked fine... But now I know. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 15:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594784#M170969</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2019-10-08T15:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594884#M171031</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202610"&gt;@Emjay&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You are right! And that's exactly why I was so confused. Cause I used my original approach with a &lt;STRONG&gt;proc freq &lt;/STRONG&gt;a while ago and there it also worked fine... But now I know. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I use formats to validate some long lists of values and sometime use things like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if put(variable, validformatname.) = 'Valid' then &amp;lt;what I wanted to do&amp;gt;;
Else do &amp;lt;whatever when the value isn't on the valid list&amp;gt;;&lt;/PRE&gt;
&lt;P&gt;You should be able to use:&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table why_dup as
select distinct put(KBZ,KBZrange. ) as KBZ_range from have;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 19:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594884#M171031</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-08T19:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why does proc format create duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594965#M171080</link>
      <description>&lt;P&gt;I've seen this format approach in if-statements but I never understood the benefit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would be the reason to rather write:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value KBZ2range (FUZZ=0)
low-1 = "valid" 
1&amp;lt;-2 = "nv" 
2&amp;lt;-3 = "valid"
3&amp;lt;-4 = "nv"
4&amp;lt;-5 = "valid"
5&amp;lt;-high = "nv";
quit;

data foo;
set have;
if put(KBZ,KBZ2range.)='valid' then check='yes'; 
else check='no';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Instead of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo2;
set have;
if (KBZ&amp;lt;=1 or 2&amp;lt;KBZ&amp;lt;=3 or 4&amp;lt;KBZ&amp;lt;=5) then check='yes'; 
else check='no';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A lot of extra typing...&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 07:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-proc-format-create-duplicates/m-p/594965#M171080</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2019-10-09T07:17:46Z</dc:date>
    </item>
  </channel>
</rss>

