SAS Enterprise Guide

Desktop productivity for business analysts and programmers
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1190 views
  • 1 like
  • 3 in conversation