From: Sdlentertd on
I have a numeric field and i need to convert it into character field
that is 7 digits.
so if i have numeric 1234567 then the character will be 1234567
if i have numeric 123456 then the character should be with a leading
0 : 0123456
If i have numeric 12345678 then the character field should be 2345678
- dropping the first digit.
so if it's 7 digits then it's fine, if it's less than 7 digits add
leading 0s and if it's more than 7 then only grab 7 digits starting
from the right.


i have this code but it only converts to character and adds leading 0s
where needed, but what if it's more than 7 i don't know how to tell
SAS to grab first 7 from the right.
New_char = put(input(Old_num,12.0),z7.);

Thank you
From: Ya on
On Jul 20, 9:51 am, Sdlentertd <sdlente...(a)gmail.com> wrote:
> I have a numeric field and i need to convert it into character field
> that is 7 digits.
> so if i have numeric 1234567 then the character will be 1234567
> if i have numeric 123456 then the character should be with a leading
> 0 : 0123456
> If i have numeric 12345678 then the character field should be 2345678
> - dropping the first digit.
> so if it's 7 digits then it's fine, if it's less than 7 digits add
> leading 0s and if it's more than 7 then only grab 7 digits starting
> from the right.
>
> i have this code but it only converts to character and adds leading 0s
> where needed, but what if it's more than 7 i don't know how to tell
> SAS to grab first 7 from the right.
> New_char = put(input(Old_num,12.0),z7.);
>
> Thank you

New_char = substr(put(input(Old_num,
12.0),z7.),length(put(input(Old_num,12.0),z7.)-6));

From: Ya on
On Jul 20, 10:08 am, Ya <huang8...(a)gmail.com> wrote:
> On Jul 20, 9:51 am, Sdlentertd <sdlente...(a)gmail.com> wrote:
>
>
>
>
>
> > I have a numeric field and i need to convert it into character field
> > that is 7 digits.
> > so if i have numeric 1234567 then the character will be 1234567
> > if i have numeric 123456 then the character should be with a leading
> > 0 : 0123456
> > If i have numeric 12345678 then the character field should be 2345678
> > - dropping the first digit.
> > so if it's 7 digits then it's fine, if it's less than 7 digits add
> > leading 0s and if it's more than 7 then only grab 7 digits starting
> > from the right.
>
> > i have this code but it only converts to character and adds leading 0s
> > where needed, but what if it's more than 7 i don't know how to tell
> > SAS to grab first 7 from the right.
> > New_char = put(input(Old_num,12.0),z7.);
>
> > Thank you
>
> New_char = substr(put(input(Old_num,
> 12.0),z7.),length(put(input(Old_num,12.0),z7.)-6));- Hide quoted text -
>
> - Show quoted text -

Actually, you need to change z7. to z12. too.
From: Ed on
have you tried new_char=substr(put(input(old_num,12.0),z12.),6,7)?

Sdlentertd wrote:
>
> I have a numeric field and i need to convert it into character field
> that is 7 digits.
> so if i have numeric 1234567 then the character will be 1234567
> if i have numeric 123456 then the character should be with a leading
> 0 : 0123456
> If i have numeric 12345678 then the character field should be 2345678
> - dropping the first digit.
> so if it's 7 digits then it's fine, if it's less than 7 digits add
> leading 0s and if it's more than 7 then only grab 7 digits starting
> from the right.
>
> i have this code but it only converts to character and adds leading 0s
> where needed, but what if it's more than 7 i don't know how to tell
> SAS to grab first 7 from the right.
> New_char = put(input(Old_num,12.0),z7.);
>
> Thank you
From: Sdlentertd on
On Jul 20, 10:08 am, Ya <huang8...(a)gmail.com> wrote:
> On Jul 20, 9:51 am, Sdlentertd <sdlente...(a)gmail.com> wrote:
>
>
>
>
>
> > I have a numeric field and i need to convert it into character field
> > that is 7 digits.
> > so if i have numeric 1234567 then the character will be 1234567
> > if i have numeric 123456 then the character should be with a leading
> > 0 : 0123456
> > If i have numeric 12345678 then the character field should be 2345678
> > - dropping the first digit.
> > so if it's 7 digits then it's fine, if it's less than 7 digits add
> > leading 0s and if it's more than 7 then only grab 7 digits starting
> > from the right.
>
> > i have this code but it only converts to character and adds leading 0s
> > where needed, but what if it's more than 7 i don't know how to tell
> > SAS to grab first 7 from the right.
> > New_char = put(input(Old_num,12.0),z7.);
>
> > Thank you
>
> New_char = substr(put(input(Old_num,
> 12.0),z7.),length(put(input(Old_num,12.0),z7.)-6));- Hide quoted text -
>
> - Show quoted text -
It doesn't work, the field is blank in teh output
New_char= substr(put(input(Old_num,12.0),z7.),
length(put(input(Old_num,12.0),z7.)-6));