Hoe do the codes in the other dataset with the character variable look like?
@bhca60 wrote:
It looks like it worked but there is an ID that has a leading zero like 099999 but still shows as 99999.
Shows where?
If you send values to a spreadsheet quite often the rules of the spreadsheet will convert text containing digits to numeric which loses the leading zeros.
That's why you need to use the Z format, which prints leading zeroes.
Numbers do not have leading zeroes. You must force the display of leading zeroes by using the proper format during the conversion to character.
ID_char = put(input(id_char, 8.), 8. -l)
Then you can use the Z6 format in your conversion.
ID_char = put(trim(ID), z6. -l);
@Reeza wrote:
Then you can use the Z6 format in your conversion.
ID_char = put(trim(ID), z6. -l);
Do not use the TRIM() function with a NUMERIC variable.
There is no need to use the -L modifier with the Z format as there will not be any leading spaces to remove.
ID_char = put(ID, z6.);
@bhca60 - It is normally better to fix this problem in Excel and then re-import. Open Excel, select the ID column. In the Data tab, select the Text to Column wizard, and go through the dialog, selecting Text as your column type. Now, when you re-import into SAS your ID column type will stay as character.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.