BookmarkSubscribeRSS Feed
raivester
Quartz | Level 8

I have a variable that is character that I am trying to convert numeric and ensure leading zeros. I have attempted the following, but get the message: Format $Z was not found or could not be loaded.

 

length ocounty $2. oid $6.;
	if NCRPV1   ne . then ocounty 	= strip(put(NCRPV1,z2.));

Can someone help resolve this?

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Try to make you numeric and then convert back to char using Z format

 

strip(put(input(NCRPV1,32.),z2.));

You can't apply a Z format for a char value. You need your value to standard numeric data. So you need INPUT function first 

Kurt_Bremser
Super User

To convert character to numeric, you need the INPUT function.

ocounty  = input(NCRPV1,2.);
format ocounty z2.;

But if the data is some kind of a code for something, keep it as character.

Tom
Super User Tom
Super User

Character variables require character formats. So the data step compiler converted the attempt to use the numeric Z format with the character variable NCRPV1 into a request for the character format $Z.  SAS does not delivery such a format and it couldn't find a user defined one either.

 

You first need to figure out whether NCRPV1 is supposed to be numeric or character in order to decide if you need to change your program or change your data.

SASKiwi
PROC Star

The error suggests your variable NCRPV1 is already character. If you want to add leading zeros then you will need to do this:

 

if NCRPV1   ne '' then ocounty 	= strip(put(input(NCRPV1, 2.),z2.));

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 10548 views
  • 0 likes
  • 5 in conversation