SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

concat a numeric column into a char with a leading '0'

Accepted Solution Solved
Reply
Highlighted
Contributor
Posts: 38
Accepted Solution

concat a numeric column into a char with a leading '0'

 I'm processing a table with DI Studio (4.901)

 

I have a column that is numeric (best6.) input.. I need to convert the column to character (char40).. (simple enough)

BUT, if the numeric value of the input column is less than/equal to 99.... I need to add a zero to the leading side of the value in it's character result. I have to use this result character column to join with another table..   so a value of 99 needs to be '099' 

 

I tried to use a case statement such as :

case

when <= 99

then cat('0', numeric_column)

else numeric_column

end

 

when I try to validate the code I get this error:

71 proc sql;
72 validate
73 select case
74 when <= 99
__
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.

75 then cat (0, channel_code)
76 else channel_code
77 end from work.etls_EFITable;

 

 

I think I'm just overlooking something simple in my logic..

Regards.

 

- Chris N.

Accepted Solutions
Solution
‎10-06-2017 11:11 AM
Respected Advisor
Posts: 2,179

Re: concat a numeric column into a char with a leading '0'

You want to use the Z format

 

something like

 

charvar=put(numvar,z3.);
--
Paige Miller

View solution in original post


All Replies
Solution
‎10-06-2017 11:11 AM
Respected Advisor
Posts: 2,179

Re: concat a numeric column into a char with a leading '0'

You want to use the Z format

 

something like

 

charvar=put(numvar,z3.);
--
Paige Miller
Contributor
Posts: 38

Re: concat a numeric column into a char with a leading '0'

Posted in reply to PaigeMiller

wow.. that was incredibly quick and painless.

that tried and worked excellent. I'm looking up that Z format to learn more about it.

 

Thanks for the help!

- Chris N.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 450 views
  • 2 likes
  • 2 in conversation