<?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: SAS separating out variables that are the same in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623322#M183494</link>
    <description>&lt;P&gt;To remove leading spaces use LEFT() function.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=left(var);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that assumes the leading characters are actually spaces and not some other non-printing character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the leading characters in your data?&lt;/P&gt;
&lt;P&gt;Try running your proc freq but format the variable using $HEX2. format so that you will just see the hex code for the first characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normal characters are in general the values between space '20'x and tilda '7E'x.&lt;/P&gt;
&lt;P&gt;'30'x to '39'x are the digits.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'41'x&amp;nbsp; is uppercase A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some common invisible characters:&lt;/P&gt;
&lt;P&gt;'20'x is a space.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'00'x is a binary zero.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'09'x is a tab.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'0A'x is a linefeed.&lt;/P&gt;
&lt;P&gt;'0D'x is a carriage return.&lt;/P&gt;
&lt;P&gt;'A0'x is the goofy character Microsoft invented to use as a non-breaking space for typesetting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To remove those characters you can use compress&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=compress(var,'090A0D00A0'x);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or convert them to spaces using translate:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=left(translate(var,'     ','00090A0DA0'x));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 08 Feb 2020 17:39:40 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-08T17:39:40Z</dc:date>
    <item>
      <title>SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623299#M183474</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running a proc freq for a numerical variable - and SAS is generating separate rows for the same numbers. For instance, it goes in chronological order w/ the frequencies from 1 to 156, then after that it starts going through lower numbers again. So there may be fifteen 1s, but SAS is separating them into one group of 8 and one group of 7 in the proc freq - essentially reporting the response of '1' as separate responses when it is the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've checked that in the input data the font/size/spacing of these variables is all the same. Is there a way I can program for it to stop doing that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 14:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623299#M183474</guid>
      <dc:creator>rebecca8</dc:creator>
      <dc:date>2020-02-08T14:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623302#M183477</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301681"&gt;@rebecca8&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the type of the variable character or numeric? Have they a format?&lt;/P&gt;
&lt;P&gt;You can run a PROC CONTENTS to see this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc contents data=have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is character, could you please run the following program to see if there are some trailing blanks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
	set have;
	if prxmatch('/\s/',my_var) &amp;gt; 0 then flag=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(replace 'my_var' by you variable name and 'have' by your dataset name)&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 15:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623302#M183477</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-08T15:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623303#M183478</link>
      <description>&lt;P&gt;You will need to show examples of the values that are at issue to get a complete answer. But if PROC FREQ considers the values as different then they are different.&amp;nbsp;You cannot fix it without changing the values that PROC FREQ is grouping by.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your variable numeric or character?&amp;nbsp; If character do the values have different numbers of leading spaces?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length name2 $30;
  set sashelp.class(obs=3);
  name2=name;
  output;
  name2=' '||name2;
  output;
  name2=' '||name2;
  output;
run;

proc freq data=test;
tables name name2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;The FREQ Procedure

                                    Cumulative    Cumulative
Name       Frequency     Percent     Frequency      Percent
------------------------------------------------------------
Alfred            3       33.33             3        33.33
Alice             3       33.33             6        66.67
Barbara           3       33.33             9       100.00


                                      Cumulative    Cumulative
name2        Frequency     Percent     Frequency      Percent
--------------------------------------------------------------
  Alfred            1       11.11             1        11.11
  Alice             1       11.11             2        22.22
  Barbara           1       11.11             3        33.33
 Alfred             1       11.11             4        44.44
 Alice              1       11.11             5        55.56
 Barbara            1       11.11             6        66.67
Alfred              1       11.11             7        77.78
Alice               1       11.11             8        88.89
Barbara             1       11.11             9       100.00&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2020 15:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623303#M183478</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-08T15:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623320#M183492</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran this, and there does appear to be some trailing/leading spaces. But when I try either the trim or the strip function, it doesn't seem to make a difference and the table is still generating identical variables out separately.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions moving forward?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 17:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623320#M183492</guid>
      <dc:creator>rebecca8</dc:creator>
      <dc:date>2020-02-08T17:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623322#M183494</link>
      <description>&lt;P&gt;To remove leading spaces use LEFT() function.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=left(var);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that assumes the leading characters are actually spaces and not some other non-printing character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the leading characters in your data?&lt;/P&gt;
&lt;P&gt;Try running your proc freq but format the variable using $HEX2. format so that you will just see the hex code for the first characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normal characters are in general the values between space '20'x and tilda '7E'x.&lt;/P&gt;
&lt;P&gt;'30'x to '39'x are the digits.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'41'x&amp;nbsp; is uppercase A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some common invisible characters:&lt;/P&gt;
&lt;P&gt;'20'x is a space.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'00'x is a binary zero.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'09'x is a tab.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'0A'x is a linefeed.&lt;/P&gt;
&lt;P&gt;'0D'x is a carriage return.&lt;/P&gt;
&lt;P&gt;'A0'x is the goofy character Microsoft invented to use as a non-breaking space for typesetting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To remove those characters you can use compress&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=compress(var,'090A0D00A0'x);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or convert them to spaces using translate:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var=left(translate(var,'     ','00090A0DA0'x));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2020 17:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623322#M183494</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-08T17:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623324#M183496</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301681"&gt;@rebecca8&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you could try to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
	set have;
	num_2=compress(num);

proc freq data=have2;
	tables num_2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2020 18:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623324#M183496</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-08T18:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623326#M183498</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;noted, there are other characters that won't be visible, but can still be part of your variable.&amp;nbsp; Leading blanks are one possibility, but other characters can cause a similar problem.&amp;nbsp; Luckily, it's easy to get rid of all non-digits:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var = compress(var, , 'kd' );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KD = Keep Digits, and any other characters will be removed.&amp;nbsp; Apply that statement to your data, and see if there is still a problem with the PROC FREQ.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 18:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623326#M183498</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-08T18:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS separating out variables that are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623328#M183499</link>
      <description>&lt;P&gt;Amazing! Thank you for all the help and the detailed explanations. Problem solved &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 18:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-separating-out-variables-that-are-the-same/m-p/623328#M183499</guid>
      <dc:creator>rebecca8</dc:creator>
      <dc:date>2020-02-08T18:28:39Z</dc:date>
    </item>
  </channel>
</rss>

