<?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 Drop char var based on length in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578078#M13292</link>
    <description>&lt;P&gt;Hallo once again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an ID variable called “CPR” which must be 10 characters long.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its a char var with numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to drop those observations who doesn’t meet this criteria.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code look like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date have;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if lengthn(cpr) &amp;lt;10 then drop;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anyone help ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;kind regards Frank&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2019 13:44:10 GMT</pubDate>
    <dc:creator>frakje</dc:creator>
    <dc:date>2019-07-31T13:44:10Z</dc:date>
    <item>
      <title>Drop char var based on length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578078#M13292</link>
      <description>&lt;P&gt;Hallo once again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an ID variable called “CPR” which must be 10 characters long.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its a char var with numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to drop those observations who doesn’t meet this criteria.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code look like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date have;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set want;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if lengthn(cpr) &amp;lt;10 then drop;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can anyone help ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;kind regards Frank&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 13:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578078#M13292</guid>
      <dc:creator>frakje</dc:creator>
      <dc:date>2019-07-31T13:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Drop char var based on length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578086#M13293</link>
      <description>&lt;P&gt;Drop is a declarative statement that can't be executed conditionally, as it is meant to alter the data structure.&lt;/P&gt;
&lt;P&gt;If you want to get rid of observattons with faulty entries, use a where condition, a subsetting if, or a conditional delete:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* method with where */
date have; 
set want; 
where lengthn(cpr) ge 10;
run;

/* subsetting if */
date have; 
set want; 
if lengthn(cpr) ge 10;
run;

/* delete */
date have; 
set want; 
if lengthn(cpr) &amp;lt; 10 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The most performant of these three is the where.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 13:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578086#M13293</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-31T13:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Drop char var based on length</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578091#M13295</link>
      <description>&lt;P&gt;In real life, data mistakes come in all shapes and sizes.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There might be leading blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There might be letters mixed in with the numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There might be values that are longer than 10 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to keep observations that have exactly 10 digits, consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if length(compress(cpr, , 'kd') ) = 10;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 14:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Drop-char-var-based-on-length/m-p/578091#M13295</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-31T14:07:40Z</dc:date>
    </item>
  </channel>
</rss>

