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)
| COCD | Required Output |
| 1 | 0001 |
| 2 | 0002 |
| 11 | 0011 |
| 22 | 0022 |
| 333 | 0333 |
| 4444 | 4444 |
Regards,
Shaheen
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.