<?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 How to replace character value with range of values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920191#M362420</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a dataset with a variable "age" that is continuous, but contains "&amp;lt;1". I am looking to replace the "&amp;lt;1" with a range of numeric values (0.3-0.7).&amp;nbsp; The data I have is for individuals and looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;                    
input individual age visit;
datalines;
1 &amp;lt;1  1
1 12  2
1 13  3
2 &amp;lt;1  1
2  4  2
2  5  3
3 &amp;lt;1  1
4 &amp;lt;1  1
5 &amp;lt;1  1
6  3  1
7  9  1
8 &amp;lt;1  1
;
run;&lt;/PRE&gt;&lt;P&gt;I can't seem to figure out what code may work. I initially though proc MI but that may be overcomplicating the situation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2024 20:08:13 GMT</pubDate>
    <dc:creator>Bumble_15</dc:creator>
    <dc:date>2024-03-13T20:08:13Z</dc:date>
    <item>
      <title>How to replace character value with range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920191#M362420</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a dataset with a variable "age" that is continuous, but contains "&amp;lt;1". I am looking to replace the "&amp;lt;1" with a range of numeric values (0.3-0.7).&amp;nbsp; The data I have is for individuals and looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;                    
input individual age visit;
datalines;
1 &amp;lt;1  1
1 12  2
1 13  3
2 &amp;lt;1  1
2  4  2
2  5  3
3 &amp;lt;1  1
4 &amp;lt;1  1
5 &amp;lt;1  1
6  3  1
7  9  1
8 &amp;lt;1  1
;
run;&lt;/PRE&gt;&lt;P&gt;I can't seem to figure out what code may work. I initially though proc MI but that may be overcomplicating the situation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 20:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920191#M362420</guid>
      <dc:creator>Bumble_15</dc:creator>
      <dc:date>2024-03-13T20:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace character value with range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920195#M362422</link>
      <description>&lt;P&gt;Can you give us more info on what your imputation rules are?&lt;/P&gt;&lt;P&gt;This example uses the rand function. If you can provide your imputation rules, we can advise better&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
input individual age $ visit;
datalines;
1 &amp;lt;1&amp;nbsp; 1
1 12&amp;nbsp; 2
1 13&amp;nbsp; 3
2 &amp;lt;1&amp;nbsp; 1
2&amp;nbsp; 4&amp;nbsp; 2
2&amp;nbsp; 5&amp;nbsp; 3
3 &amp;lt;1&amp;nbsp; 1
4 &amp;lt;1&amp;nbsp; 1
5 &amp;lt;1&amp;nbsp; 1
6&amp;nbsp; 3&amp;nbsp; 1
7&amp;nbsp; 9&amp;nbsp; 1
8 &amp;lt;1&amp;nbsp; 1
;
run;

data want;
set have;
if age&amp;nbsp; = "&amp;lt;1" then age2 = rand('uniform', 0.3, 0.7);
else age2=input(age,best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 13 Mar 2024 20:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920195#M362422</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-13T20:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace character value with range of values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920196#M362423</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464161"&gt;@Bumble_15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a dataset with a variable "age" that is continuous, but contains "&amp;lt;1". I am looking to replace the "&amp;lt;1" with a range of numeric values (0.3-0.7).&amp;nbsp; The data I have is for individuals and looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;                    
input individual age visit;
datalines;
1 &amp;lt;1  1
1 12  2
1 13  3
2 &amp;lt;1  1
2  4  2
2  5  3
3 &amp;lt;1  1
4 &amp;lt;1  1
5 &amp;lt;1  1
6  3  1
7  9  1
8 &amp;lt;1  1
;
run;&lt;/PRE&gt;
&lt;P&gt;I can't seem to figure out what code may work. I initially though proc MI but that may be overcomplicating the situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That description is not very clear. Do you want to replace some of the &amp;lt;1 with a single value of 0.3, and others with a single value of 0.4, 0.5 (or other single numeric values) or do want the &amp;lt;1 to display in printed output as (0.3-0.7)?&lt;/P&gt;
&lt;P&gt;The latter display option would be to use a custom format.&lt;/P&gt;
&lt;P&gt;If you want to randomly assign a numeric value in the range of 0.3 to 0.7 then questions come up about how many decimals do you want to allow in that range. The RAND function with the UNIFORM option will create numeric values in an interval.&lt;/P&gt;
&lt;PRE&gt;data junk;
  do i=1 to 25;
    x=rand('uniform',.03,.07) ;
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Round the values if you don't want lots of decimals.&lt;/P&gt;
&lt;P&gt;To convert your existing data: (You would have to read age a character to get a value like "&amp;lt;1")&lt;/P&gt;
&lt;PRE&gt;data have;                    
input individual age $ visit;
datalines;
1 &amp;lt;1  1
1 12  2
1 13  3
2 &amp;lt;1  1
2  4  2
2  5  3
3 &amp;lt;1  1
4 &amp;lt;1  1
5 &amp;lt;1  1
6  3  1
7  9  1
8 &amp;lt;1  1
;
data want;
   set have;
   if age='&amp;lt;1' then agenum= rand('UNIFORM',0.3,0.7);
   else agenum = input(age,2.);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 20:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-character-value-with-range-of-values/m-p/920196#M362423</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-13T20:30:48Z</dc:date>
    </item>
  </channel>
</rss>

