<?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: Working with junk chars in SAS, while creating new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289266#M59738</link>
    <description>&lt;P&gt;You can use the COMPRESS function to remove the nulls ('00'X). &amp;nbsp;Or you could change them to spaces by using the TRANSLATE() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var = translate(var,' ','00'x);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Aug 2016 15:32:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-08-03T15:32:08Z</dc:date>
    <item>
      <title>Working with junk chars in SAS, while creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289252#M59735</link>
      <description>&lt;P&gt;I have a SAS dataset. that has a column that contains text data. There are instances where the field is empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if we use the indicator &amp;gt;&amp;gt;if var=" " then x1=1;else x1=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Problem is, it is not capturing all the spaces. There are some spaces left, which still have value 0. I assume, these might be junk chars, which are not getting displayed. How can I deal with this situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have already tried compress, strip,trim etc. I just printed the hex values and it seems it has 2 cases '00'(NULL) and '20'(space)&lt;/P&gt;
&lt;P&gt;For space condition it works, but for null it fails. Is there a way to treat it, without coverting to HEX?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289252#M59735</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2016-08-03T15:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Working with junk chars in SAS, while creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289258#M59737</link>
      <description>&lt;P&gt;Without seeing the data and the logic we wouldn't be able to say. &amp;nbsp;The functions you have given: strip(), trim() remove blanks, compress() can be used to keep or drop various characters/groups of characters. &amp;nbsp;They should be sufficient for the purpose.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289258#M59737</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-03T15:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Working with junk chars in SAS, while creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289266#M59738</link>
      <description>&lt;P&gt;You can use the COMPRESS function to remove the nulls ('00'X). &amp;nbsp;Or you could change them to spaces by using the TRANSLATE() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var = translate(var,' ','00'x);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289266#M59738</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-08-03T15:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Working with junk chars in SAS, while creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289268#M59739</link>
      <description>&lt;P&gt;It's easy enough to change your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if var in (' ', '00'x) then x1=1;&lt;/P&gt;
&lt;P&gt;else x1=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are complications, however, if your variable is defined as being more than one character long.&amp;nbsp; For example, if your variable is 5 characters long, you might actually have 5 nulls there, rather than one null with four blanks.&amp;nbsp; The logic above wouldn't pick up 5 nulls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For longer variables, another variation would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if var in : (' ', '00'x) then x1=1;&lt;/P&gt;
&lt;P&gt;else x1=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will compare just the first character of your variable, looking for blanks and nulls.&amp;nbsp; That may be acceptable, but it depends on whether you might have data values that begin with a blank (or a null) but contain actual text afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The tools are there, it's really a matter of knowing what's in the data.&amp;nbsp; Your best bet might be to forget about creating X1.&amp;nbsp; Just use the TRANSLATE function to convert all nulls into blanks.&amp;nbsp; That would certainly make later programming easier as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;***** EDITED:&amp;nbsp; I see that Tom already posted the syntax for TRANSLATE, as I was typing my answer.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-junk-chars-in-SAS-while-creating-new-variables/m-p/289268#M59739</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-03T15:39:34Z</dc:date>
    </item>
  </channel>
</rss>

