BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cnilsen
Quartz | Level 8

 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.
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You want to use the Z format

 

something like

 

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

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

You want to use the Z format

 

something like

 

charvar=put(numvar,z3.);
--
Paige Miller
cnilsen
Quartz | Level 8

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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