BookmarkSubscribeRSS Feed
Shah
Obsidian | Level 7

I have tried the above tostring function and it is working fine. Thank you so much for the above solution and also regret for the late reply.

I have one more question to ask, I have the field COCD with the len 1, 2, 3, and 4 digits. The COCD column must consist of 4 len number as per our requirement so i have to prefix each company code with '0' to make it 4 digit. Is there any solution or functionality i can use to change the len to 4 digits?

I have used below the expression but not yielding result:

if len(COCD) == 1 then cocd_text = left(000,COCD)

COCDRequired Output
10001
20002
110011
220022
3330333
44444444


Regards,
Shaheen

1 REPLY 1
skillman
SAS Employee

This was answered here:

but to save you a click here is the solution:

/* Pre-processing Expression*/

string desired_output

hidden integer i

desired_output = ''

i = 0

/*Expression*/

if len(`COCD`) < 4

  begin

  desired_output = `COCD`

  while i <  (4 - len(`COCD`))

  begin

  desired_output = '0' & desired_output

  i = i + 1

  end

  end

else

  desired_output = `COCD`

  i = 0

dm_expression.png

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 1125 views
  • 0 likes
  • 2 in conversation