<?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: Subsetting If statement not working as expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716933#M221655</link>
    <description>&lt;P&gt;Maxim 2: Read the Log. You will see a NOTE about conversion of numeric to character.&lt;/P&gt;
&lt;P&gt;LENGTH is a character function, so the numeric value is converted with the BEST12. format, right-aligned, which causes your LENGTH call to return an unexpected result.&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if length(strip(put('Industry classification code'n,best.))) = 6;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 100000 le 'Industry classification code'n le 999999;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Feb 2021 22:22:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-02-04T22:22:28Z</dc:date>
    <item>
      <title>Subsetting If statement not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716924#M221650</link>
      <description>&lt;P&gt;hello,&amp;nbsp; i'm trying to use a subsetting to filter a dataset.&amp;nbsp; &amp;nbsp;I imported a .csv file into SAS.&amp;nbsp; import worked as expected, but when I try to filter the dataset using the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;length Industry_classification_code $10;&lt;/P&gt;&lt;P&gt;Industry_classification_code = 'Industry classification code'n;&lt;BR /&gt;if length(trim(Industry_classification_code)) = 6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset is get created without any rows.&amp;nbsp; &amp;nbsp;I checked my dataset before the if statment.&amp;nbsp; Even did a proc freq, the values are there.&amp;nbsp; &amp;nbsp;'Industry classification code'n is a numeric variable values look like:&lt;/P&gt;&lt;P&gt;92000&lt;/P&gt;&lt;P&gt;92011&lt;/P&gt;&lt;P&gt;529983&lt;/P&gt;&lt;P&gt;674552&lt;/P&gt;&lt;P&gt;I'm trying to keep rows where there are six digits in the variable,&amp;nbsp; like the last two rows above.&amp;nbsp; Something is wrong, not sure what.&amp;nbsp; Any assistance would be greatly appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 22:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716924#M221650</guid>
      <dc:creator>covershaker</dc:creator>
      <dc:date>2021-02-04T22:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting If statement not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716932#M221654</link>
      <description>&lt;P&gt;You say the variable is numeric. That means that the length is very likely to be 8 as that is the default length for numeric values. If you want to convert the variable to character so you get an expected length try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Length (put('Industry classification code'n , f10. -L)&lt;/P&gt;
&lt;P&gt;The put creates a character value using the format F10, using you apparently desired length. The -L means to left justify the result. A numeric 92000 would then become "92000&amp;nbsp;&amp;nbsp; ". The Length function will ignore trailing blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see the result with this:&lt;/P&gt;
&lt;PRE&gt;data junk;
   x= 92000;
   l = length(put(x,f10. -L));
run;&lt;/PRE&gt;
&lt;P&gt;Personally I read CSV files so the variables are of the types I want using a data step. I suspect you allowed Proc Import to create a SAS data set and because of options set you now have 1) name literals like that ugly thing that are somewhat awkward to code with, and 2) variables of the incorrect type.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 22:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716932#M221654</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-04T22:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting If statement not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716933#M221655</link>
      <description>&lt;P&gt;Maxim 2: Read the Log. You will see a NOTE about conversion of numeric to character.&lt;/P&gt;
&lt;P&gt;LENGTH is a character function, so the numeric value is converted with the BEST12. format, right-aligned, which causes your LENGTH call to return an unexpected result.&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if length(strip(put('Industry classification code'n,best.))) = 6;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 100000 le 'Industry classification code'n le 999999;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Feb 2021 22:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716933#M221655</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-04T22:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting If statement not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716935#M221656</link>
      <description>Thanks for the quick response. That did the trick.</description>
      <pubDate>Thu, 04 Feb 2021 22:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting-If-statement-not-working-as-expected/m-p/716935#M221656</guid>
      <dc:creator>covershaker</dc:creator>
      <dc:date>2021-02-04T22:54:57Z</dc:date>
    </item>
  </channel>
</rss>

