From: Henry on
Dear all,

I have a very simple question.

I tried to add the leading zeros before the values like:
111
112
113

I will like to have the following:
0111
0112
0113


I use the put function like

data new;
set old;
newsic= put(sic, z4.);
run;


But the log gives me this information:
ERROR 48-59: The format $Z was not found or could not be loaded.

I am not sure if there is any problem as it seems to be easy??

Any suggestions? Thank you so mcuh!
From: Tom Abernathy on
Henry -
The error message is saying that your old variable SIC was already a
character variable and not a number.
You can convert it to a number with the INPUT function.

newsic = put( input(sic,4.), z4. );

You could also just prefix the zeros as characters.
if length(sic) >= 4 then newsic=sic;
else newsic=repeat('0',4-length(sic)-1)||sic;

Note that the -1 is needed because the REPEAT function counts funny.

- Tom

On Mar 8, 9:57 pm, Henry <chchanghe...(a)gmail.com> wrote:
> Dear all,
>
> I have a very simple question.
>
> I tried to add the leading zeros before the values like:
> 111
> 112
> 113
>
> I will like to have the following:
> 0111
> 0112
> 0113
>
> I use the put function like
>
> data new;
>         set old;
>         newsic= put(sic, z4.);
>         run;
>
> But the log gives me this information:
> ERROR 48-59: The format $Z was not found or could not be loaded.
>
> I am not sure if there is any problem as it seems to be easy??
>
> Any suggestions?  Thank you so mcuh!

From: Henry on
Hi Tom,

I found the problem after posting it. I actually followed the second
way as you suggested. Thank you so much for your prompt reply!!!




On Mar 8, 8:58 pm, Tom Abernathy <tom.aberna...(a)gmail.com> wrote:
> Henry -
>   The error message is saying that your old variable SIC was already a
> character variable and not a number.
>   You can convert it to a number with the INPUT function.
>
>     newsic = put( input(sic,4.), z4. );
>
>   You could also just prefix the zeros as characters.
>     if length(sic) >= 4 then newsic=sic;
>     else newsic=repeat('0',4-length(sic)-1)||sic;
>
> Note that the -1 is needed because the REPEAT function counts funny.
>
> - Tom
>
> On Mar 8, 9:57 pm, Henry <chchanghe...(a)gmail.com> wrote:
>
> > Dear all,
>
> > I have a very simple question.
>
> > I tried to add the leading zeros before the values like:
> > 111
> > 112
> > 113
>
> > I will like to have the following:
> > 0111
> > 0112
> > 0113




>
> > I use the put function like
>
> > data new;
> >         set old;
> >         newsic= put(sic, z4.);
> >         run;
>
> > But the log gives me this information:
> > ERROR 48-59: The format $Z was not found or could not be loaded.
>
> > I am not sure if there is any problem as it seems to be easy??
>
> > Any suggestions?  Thank you so mcuh!