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?
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.)) ;
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.)) ;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.