[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: character to numeric - variables mixed letters and numbers
From:       Stanford Mwasongwe <smwasongwe () GMAIL ! COM>
Date:       2021-10-14 14:29:10
Message-ID: CAAfzsF4Q_KCQ+8YhvtWiY+pMq+BhdwuN297EgF8xY7xm4UxfSg () mail ! gmail ! com
[Download RAW message or body]

Hi list,
Thanks again for helping. I was able to get some suggestion where the
variable stayed a character and I used the following code to assign
ascending accession numbers to the missing values
*re-assigning missing accession number;
if _n_=1 then val=0;

  if Accession_Number = ' ' then do;

    val+1;

    add=put(val,z4.);

    Accession_Number = cats(input(put(today(),yymmddn8.),8.),add);


  end;
*Stanford*



On Wed, Oct 13, 2021 at 5:40 PM Barry Grau <barry.grau@gmail.com> wrote:

> What are you really trying to do? OR, what do you really want to do,and
> for what purpose? Why do you want to convert it to a number (when we know
> that there's no such thing as a number beginning with NF or NH or...)?
>
> On Wed, Oct 13, 2021 at 11:05 AM Stanford Mwasongwe <smwasongwe@gmail.com>
> wrote:
>
>> Thanks guys!I inherited a datafile and wanted to maintain it as it is, I
>> need to find another workaround
>> *Stanford*
>>
>>
>>
>> On Wed, Oct 13, 2021 at 9:33 AM Bartosz Jabłoński <yabwon@gmail.com>
>> wrote:
>>
>>> Stanford,
>>>
>>> How do you try to convert a text variable (containing letters) into a
>>> number? What would you expect to have from "NF108930343"?
>>>
>>> Bart
>>>
>>> śr., 13 paź 2021 o 16:21 Stanford Mwasongwe <smwasongwe@gmail.com>
>>> napisał(a):
>>>
>>>> Hi list,
>>>> I've a character variable with values mixed with letters and numbers,
>>>> when I try to convert it to numeric, all the letters are removed, I need to
>>>> keep them as part of the id values. I thought a straight forward input
>>>> would do it but apparently not, thanks for the help
>>>>
>>>> data one;
>>>>
>>>>
>>>> input num $11.;
>>>>
>>>>
>>>> cards;
>>>>
>>>>
>>>> NH00528786
>>>>
>>>>
>>>> .
>>>>
>>>>
>>>> NF108930343
>>>>
>>>>
>>>> NF108989857
>>>>
>>>>
>>>> NH000381422
>>>>
>>>>
>>>> .
>>>>
>>>>
>>>> NF110680620
>>>>
>>>>
>>>> NF207424580
>>>>
>>>>
>>>> NF108981795
>>>>
>>>> data new;
>>>>
>>>>
>>>>  set one;
>>>>
>>>>
>>>>    new = input(newnum, 11.);
>>>>
>>>>
>>>>    drop num newnum;
>>>>
>>>>
>>>>    rename new=num;
>>>>
>>>>
>>>> run;
>>>> *Stanford*
>>>>
>>>>

[Attachment #3 (text/html)]

<div dir="ltr"><div dir="ltr"><div class="gmail_default" \
style="font-family:verdana,sans-serif">Hi list,</div><div class="gmail_default" \
style="font-family:verdana,sans-serif">Thanks again for helping. I was able to get \
some suggestion where the variable stayed a character and I used the following code \
to assign ascending accession numbers to the missing values</div><div \
class="gmail_default"><div class="gmail_default"><font face="verdana, \
sans-serif">*re-assigning missing accession number;</font></div><div \
class="gmail_default"><font face="verdana, sans-serif"><span \
style="white-space:pre">	</span>if _n_=1 then val=0;                                  \
</font></div><div class="gmail_default"><font face="verdana, sans-serif">  <span \
style="white-space:pre">	</span>if Accession_Number = &#39; &#39; then do;            \
</font></div><div class="gmail_default"><font face="verdana, sans-serif">   <span \
style="white-space:pre">		</span>val+1;                                               \
</font></div><div class="gmail_default"><font face="verdana, sans-serif">   <span \
style="white-space:pre">		</span>add=put(val,z4.);                                    \
</font></div><div class="gmail_default"><font face="verdana, sans-serif">   <span \
style="white-space:pre">		</span>Accession_Number = \
cats(input(put(today(),yymmddn8.),8.),add);                                           \
</font></div><div class="gmail_default"><font face="verdana, sans-serif">  <span \
style="white-space:pre">	</span>end;</font></div></div><div><div dir="ltr" \
class="gmail_signature"><div dir="ltr"><div><span style="font-size:x-small"><font \
size="2"><font><span style="font-size:10pt"><font face="bookman old style, new york, \
times, serif" color="#444444"><b>Stanford</b></font></span></font></font></span></div><div><br></div></div></div></div><br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 13, 2021 at 5:40 PM \
Barry Grau &lt;<a href="mailto:barry.grau@gmail.com">barry.grau@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div \
class="gmail_default" \
style="font-family:arial,helvetica,sans-serif;font-size:small">What are you really \
trying to do? OR, what do you really want to do,and for what purpose? Why do you want \
to convert it to a number (when we know that there&#39;s no such thing as a number \
beginning with NF or NH or...)?</div></div><br><div class="gmail_quote"><div \
dir="ltr" class="gmail_attr">On Wed, Oct 13, 2021 at 11:05 AM Stanford Mwasongwe \
&lt;<a href="mailto:smwasongwe@gmail.com" \
target="_blank">smwasongwe@gmail.com</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" \
style="font-family:verdana,sans-serif">Thanks guys!I inherited a datafile and wanted \
to maintain it as it is, I need to find another workaround </div><div><div \
dir="ltr"><div dir="ltr"><div><span style="font-size:x-small"><font \
size="2"><font><span style="font-size:10pt"><font face="bookman old style, new york, \
times, serif" color="#444444"><b>Stanford</b></font></span></font></font></span></div><div><br></div></div></div></div><br></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 13, 2021 at 9:33 AM \
Bartosz Jabłoński &lt;<a href="mailto:yabwon@gmail.com" \
target="_blank">yabwon@gmail.com</a>&gt; wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" \
style="font-family:monospace,monospace">Stanford,</div><div class="gmail_default" \
style="font-family:monospace,monospace"><br></div><div class="gmail_default" \
style="font-family:monospace,monospace">How do you try to convert a text variable \
(containing letters) into a number? What would you expect to have from &quot;<span \
style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NF108930343</span>&quot;?</div><div \
class="gmail_default" style="font-family:monospace,monospace"><br></div><div \
class="gmail_default" \
style="font-family:monospace,monospace">Bart</div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">śr., 13 paź 2021 o 16:21 \
Stanford Mwasongwe &lt;<a href="mailto:smwasongwe@gmail.com" \
target="_blank">smwasongwe@gmail.com</a>&gt; napisał(a):<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
class="gmail_default" style="font-family:verdana,sans-serif">Hi list,</div><div \
class="gmail_default" style="font-family:verdana,sans-serif">I&#39;ve a character \
variable with values mixed with letters and numbers, when I try to convert it to \
numeric, all the letters are removed, I need to keep them as part of the id values. I \
thought a straight forward input would do it but apparently not, thanks for the \
help</div><div class="gmail_default"><p \
style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">data \
one;                                                                                  \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">input \
num $11.;                                                                             \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">cards; \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NH00528786 \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">. \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NF108930343 \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NF108989857 \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NH000381422 \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">. \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NF110680620 \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NF207424580 \
</p><p style="font-family:Roboto,RobotoDraft,Helvetica,Arial,sans-serif;font-size:14px">NF108981795 \
</p><p><font face="Roboto, RobotoDraft, Helvetica, Arial, sans-serif"><span \
style="font-size:14px">data new;                                                      \
</span></font></p><p><font face="Roboto, RobotoDraft, Helvetica, Arial, \
sans-serif"><span style="font-size:14px"> set one;                                    \
</span></font></p><p><font face="Roboto, RobotoDraft, Helvetica, Arial, \
sans-serif"><span style="font-size:14px">   new = input(newnum, 11.);                 \
</span></font></p><p><font face="Roboto, RobotoDraft, Helvetica, Arial, \
sans-serif"><span style="font-size:14px">   drop num newnum;                          \
</span></font></p><p><font face="Roboto, RobotoDraft, Helvetica, Arial, \
sans-serif"><span style="font-size:14px">   rename new=num;                           \
</span></font></p><p><font face="Roboto, RobotoDraft, Helvetica, Arial, \
sans-serif"><span style="font-size:14px">run; </span></font></p></div><div><div \
dir="ltr"><div dir="ltr"><div><span style="font-size:x-small"><font \
size="2"><font><span style="font-size:10pt"><font face="bookman old style, new york, \
times, serif" color="#444444"><b>Stanford</b></font></span></font></font></span></div><div><br></div></div></div></div></div></div></div>
 </blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic