BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ccaudillo100
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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
Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 819 views
  • 1 like
  • 3 in conversation