BookmarkSubscribeRSS Feed
TashaBee
Fluorite | Level 6

I am working on a snippet where I am formatting SSN. In the past, the Z format worked, but it has not worked lately. I tried using picture (for example, picture ssfmt other = '999999999';), but that hasn't worked as well. I am getting an error that states that the format was not found or could not be loaded.

proc format;

picture ssfmt low-high = '999999999';

run;

ID starts of with a character of 20 length. Then I do the following:

length newid $9.;

newid =idnumber;

newssn = input(newid, ssfmt.);

Any pointers?

Thanks,

10 REPLIES 10
data_null__
Jade | Level 19

Why no use the SSN format.

data _null_;
   ssn=
000090201;
  
put ssn ssn.;
  
run;

000-09-0201
TashaBee
Fluorite | Level 6

Thanks for the reply, but I am getting the error that the format could not be found or loaded.

Astounding
PROC Star

Is it possible that your variable is character, but in previous applications it was numeric?

TashaBee
Fluorite | Level 6

It is a character variable what I am using.

data_null__
Jade | Level 19

If it is character then perhaps you should read it (input function) into a numeric variable then apply SSN format to the new variable.

Astounding
PROC Star

As you noticed, SAS complains when you try to apply a numeric format (such as ssn. or z9.) to a character variable.  Since your variable is defined as 20 characters long, you can replace it with the proper value using the tools that data_null_ suggested:

idnumber = put(input(left(idnumber),9.), ssn.);

If you want to keep IDNUMBER as is, you could always assign this value to a new variable instead.

Good luck.

TashaBee
Fluorite | Level 6

Thank you! That worked and I did a compress to get rid of the hyphens.

Astounding
PROC Star

Ah, if you don't want the hyphens it's just slightly different:

idnumber = put(input(left(idnumber),9.), z9.);


TashaBee
Fluorite | Level 6

Thank you! I'll never understand when Z works and when it doesn't.

data_null__
Jade | Level 19

It works when the data is NUMERIC.  Does not work for character data.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 2724 views
  • 3 likes
  • 3 in conversation