12-11-2013 01:32 PM
Hello, I am a SAS newbie (3 months).
In my project, I have 3 imported data sets that I need to join together on a primary key that is a numeric type. My challenge is that in two of the tables, the leading zeros do not exist, so the join will not match for those records without the leading zeros.
What can I do to add the leading zeros to the values that are missing leading zeros? The fixed length of the field is 5, so no leading zeros should be added to the values that have a non-zero number leading (e.g 12345, 10101).
Any help would be greatly appreciated!
12-11-2013 01:50 PM
Have you actually run the join? If so was there an error or warning message? Are the variables actually of type numeric? Your comment about fixed length of 5 makes it sound that the values are likely string containing digits.
Proc contents data=table1;run; (or what ever the actual library.dataset name for table 1 would show whether actual numeric or character)
Are you trying to do this as a pass through to another database or are the tables both SAS datasets?
12-11-2013 01:52 PM
1. Numeric variables cannot have leading zeros, so it has to be a character variable.
2. You can convert the number to a character by using the SAS format Z5.
Then you can merge the fields together on the new character field or use the conversin in your PROC SQL step.
12-11-2013 01:53 PM
I'd be checking that the Table 1 import hasn't made your primary key a character variable first. If it's imported it as a number it shouldn't have the leading zeroes unless you've whacked a format on it. If that's the case convert it:
newvar = input(primary_key,5.) ;
Need further help from the community? Please ask a new question.