- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Currently I am trying to make the full fips code from the state number and county:
data Location2; set Location2B; FIPS = cats( FIPSState, County1) ; run;
For example FIPSSTATE = 01
COUNTY1 = 073
The FIPS is coming out as 173.
Is there a way I can get it to not delete the leading zeros?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am assuming that you have numeric values for FIPSSTATE and COUNTY1 and both are formatted to show leading zeros. So what you are seeing is the default handling of numeric values converting to character within CATS.
Try this, which converts the numbers to character strings with leading zeros with the Z format and then the leading zeros show up in the output from CATS
FIPS = cats( put(FIPSState,z2.), put(County1,z3.)) ;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am assuming that you have numeric values for FIPSSTATE and COUNTY1 and both are formatted to show leading zeros. So what you are seeing is the default handling of numeric values converting to character within CATS.
Try this, which converts the numbers to character strings with leading zeros with the Z format and then the leading zeros show up in the output from CATS
FIPS = cats( put(FIPSState,z2.), put(County1,z3.)) ;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The CATS() function only removes leading a trailing spaces.
Perhaps the problem is that your variables a NUMERIC instead of CHARACTER? Numbers do not have leading spaces or leading zeros. There is no difference between the number represented 1 and 01 or 000001. They are all the same number.
If you want to make a five character string from two numeric variable use the PUT() function and the Z format.
FIPS = put(FIPSState,Z2.) || put(County1,Z3.) ;
But why did your two variables get defined as numeric instead character? Perhaps you should fix the previous step that created the dataset you are using as input.