<?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: Split Numeric Variables and Replace them with String in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737488#M229936</link>
    <description>&lt;P&gt;What is a "dataframe"?&lt;/P&gt;
&lt;P&gt;What do you expect as result?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226565"&gt;@japelin&lt;/a&gt; named the main problem: you can't change the type of a variable.&lt;/P&gt;
&lt;P&gt;You could define a format and attach it to the variables. You won't see the original value, but only the text:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value Cluster
    LOW -&amp;lt; 4 = 'First Cluster'
    4 -&amp;lt; 7 = 'Second Cluster'
    7 - HIGH = 'Third Cluster'
  ;
run;

proc print data=temp_;
  format x y z Cluster.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;'t&lt;/P&gt;</description>
    <pubDate>Wed, 28 Apr 2021 04:47:02 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-04-28T04:47:02Z</dc:date>
    <item>
      <title>Split Numeric Variables and Replace them with String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737485#M229934</link>
      <description>&lt;P&gt;Here, I have a dataframe followed by&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;data temp_;&lt;BR /&gt;input x y z;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 10&lt;BR /&gt;2 5 10&lt;BR /&gt;3 6 10&lt;BR /&gt;7 1 2&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;And now i wanna classify each columns with same rules :&lt;/P&gt;&lt;P&gt;(1) variable &amp;lt; 4 then 'First Cluster'&lt;/P&gt;&lt;P&gt;(2) 4 &amp;lt;= variable &amp;lt; 7 then 'Second Cluster'&lt;/P&gt;&lt;P&gt;(3) 7&amp;lt;= variable then 'Third Cluster'.&lt;/P&gt;&lt;P&gt;Here I make an attempt,&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;data test_;&lt;BR /&gt;set temp_;&lt;BR /&gt;array level_ x -- z;&lt;BR /&gt;do over level_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if level_ &amp;lt; 4 then level_ = 'First_Cluster';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else if 4 &amp;lt;= level_ &amp;lt; 7 then level_ = 'Second_Cluster';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else if 7 &amp;lt;= level_ then level_ = 'Third_Cluster';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else level_ = 'Other';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;But what the output frame is all of null value. It seems like `array` can't be assign with string type. So can't I split numeric variable by `array`? or there is any suggestion?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for all your help !!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 04:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737485#M229934</guid>
      <dc:creator>EvansHsieh</dc:creator>
      <dc:date>2021-04-28T04:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Split Numeric Variables and Replace them with String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737487#M229935</link>
      <description>&lt;P&gt;I think this is because "level_" is a numeric array, but you are trying to assign a string to it in the do over statement, and it is not being handled correctly.&lt;BR /&gt;If you really want to use the same variable name, you need to assign it to a temporary variable and then rename it at the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_(rename=(a=x b=y c=z));
set temp_;
array level_ x -- z;
array level_C $20 a b c;
do over level_;
    if level_ &amp;lt; 4 then level_c = 'First_Cluster';
    else if 4 &amp;lt;= level_ &amp;lt; 7 then level_c = 'Second_Cluster';
    else if 7 &amp;lt;= level_ then level_c = 'Third_Cluster';
    else level_c = 'Other';
end;
drop x y z;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Apr 2021 04:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737487#M229935</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-04-28T04:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Split Numeric Variables and Replace them with String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737488#M229936</link>
      <description>&lt;P&gt;What is a "dataframe"?&lt;/P&gt;
&lt;P&gt;What do you expect as result?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226565"&gt;@japelin&lt;/a&gt; named the main problem: you can't change the type of a variable.&lt;/P&gt;
&lt;P&gt;You could define a format and attach it to the variables. You won't see the original value, but only the text:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value Cluster
    LOW -&amp;lt; 4 = 'First Cluster'
    4 -&amp;lt; 7 = 'Second Cluster'
    7 - HIGH = 'Third Cluster'
  ;
run;

proc print data=temp_;
  format x y z Cluster.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;'t&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 04:47:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737488#M229936</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-28T04:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: Split Numeric Variables and Replace them with String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737491#M229938</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361812"&gt;@EvansHsieh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here, I have a dataframe followed by&lt;/P&gt;
&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;data temp_;&lt;BR /&gt;input x y z;&lt;BR /&gt;cards;&lt;BR /&gt;1 2 10&lt;BR /&gt;2 5 10&lt;BR /&gt;3 6 10&lt;BR /&gt;7 1 2&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;And now i wanna classify each columns with same rules :&lt;/P&gt;
&lt;P&gt;(1) variable &amp;lt; 4 then 'First Cluster'&lt;/P&gt;
&lt;P&gt;(2) 4 &amp;lt;= variable &amp;lt; 7 then 'Second Cluster'&lt;/P&gt;
&lt;P&gt;(3) 7&amp;lt;= variable then 'Third Cluster'.&lt;/P&gt;
&lt;P&gt;Here I make an attempt,&lt;/P&gt;
&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;data test_;&lt;BR /&gt;set temp_;&lt;BR /&gt;array level_ x -- z;&lt;BR /&gt;do over level_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if level_ &amp;lt; 4 then level_ = 'First_Cluster';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else if 4 &amp;lt;= level_ &amp;lt; 7 then level_ = 'Second_Cluster';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else if 7 &amp;lt;= level_ then level_ = 'Third_Cluster';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else level_ = 'Other';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;But what the output frame is all of null value. It seems like `array` can't be assign with string type. So can't I split numeric variable by `array`? or there is any suggestion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for all your help !!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you read the LOG at all?&lt;/P&gt;
&lt;P&gt;The second data step shown above:&lt;/P&gt;
&lt;PRE&gt;406  data test_;
407  set temp_;
408  array level_ x -- z;
409  do over level_;
410      if level_ &amp;lt; 4 then level_ = 'First_Cluster';
411      else if 4 &amp;lt;= level_ &amp;lt; 7 then level_ = 'Second_Cluster';
412      else if 7 &amp;lt;= level_ then level_ = 'Third_Cluster';
413      else level_ = 'Other';
414  end;
415  run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      410:24   411:34   412:30   413:10
NOTE: Invalid numeric data, 'First_Cluster' , at line 410 column 33.
NOTE: Invalid numeric data, 'First_Cluster' , at line 410 column 33.
NOTE: Invalid numeric data, 'Third_Cluster' , at line 412 column 39.
x=. y=. z=. _I_=4 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, 'First_Cluster' , at line 410 column 33.
NOTE: Invalid numeric data, 'Second_Cluster' , at line 411 column 43.
NOTE: Invalid numeric data, 'Third_Cluster' , at line 412 column 39.
x=. y=. z=. _I_=4 _ERROR_=1 _N_=2
NOTE: Invalid numeric data, 'First_Cluster' , at line 410 column 33.
NOTE: Invalid numeric data, 'Second_Cluster' , at line 411 column 43.
NOTE: Invalid numeric data, 'Third_Cluster' , at line 412 column 39.
x=. y=. z=. _I_=4 _ERROR_=1 _N_=3
NOTE: Invalid numeric data, 'Third_Cluster' , at line 412 column 39.
NOTE: Invalid numeric data, 'First_Cluster' , at line 410 column 33.
NOTE: Invalid numeric data, 'First_Cluster' , at line 410 column 33.
x=. y=. z=. _I_=4 _ERROR_=1 _N_=4
NOTE: There were 4 observations read from the data set WORK.TEMP_.
NOTE: The data set WORK.TEST_ has 4 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


&lt;/PRE&gt;
&lt;P&gt;Does the phrase "Invalid numeric data, 'First_cluster' not make sense?&lt;/P&gt;
&lt;P&gt;Or the "Character values have been converted to numeric values at the places given by:" ?&lt;/P&gt;
&lt;P&gt;The log tells that you are attempting to convert character values to numeric and failing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a good idea to show what you expect for output and if the result should be a data set for further manipulation or a report that people will read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 05:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-Numeric-Variables-and-Replace-them-with-String/m-p/737491#M229938</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-28T05:37:58Z</dc:date>
    </item>
  </channel>
</rss>

