BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lydiawawa
Lapis Lazuli | Level 10

Hi All,

 

I have a dataset with a variable contains missing values, and I tried to format missing values in a separate sas file by using proc format:

 

proc format;
   value $idname '0', ., '-' ='missing';
run;

 

 

The variable in the original dataset looks like this (note: idname is formatted as string not numerical) :

idname

12367123456

12349823456

12738446324

12738495246

12734937432

.

.

.

12344837765

0

0

12344837765

 

After formatting it becomes:

 

idname

1236712

1234982

1273844

1273849

1273493

.

.

.

1234483

0

0

1234483

 

It seems the word 'missing' caused the cut off to carry over only the first 7 characters after formatting. Does anyone know how to resolve the issue?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

So you only worry about the truncating, not the format is NOT working 🙂

proc format;
   value $idname '0',' ' , '-' ='missing';
run;

data test;
infile cards truncover;
input id $20.;
format id $idname20.;

cards;
12367123456
12349823456
12738446324
12738495246
12734937432
.
.
.
12344837765
0
0
12344837765
;

 

give it enough length, it will show.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

It looks like the format is truncating what prints.  It won't truncate the actual value.  Try specifying a width when applying the format:

 

format varname $idname11.;

 

 

Haikuo
Onyx | Level 15

So you only worry about the truncating, not the format is NOT working 🙂

proc format;
   value $idname '0',' ' , '-' ='missing';
run;

data test;
infile cards truncover;
input id $20.;
format id $idname20.;

cards;
12367123456
12349823456
12738446324
12738495246
12734937432
.
.
.
12344837765
0
0
12344837765
;

 

give it enough length, it will show.

ballardw
Super User

Formats all have a default width or number of characters that display.

If you note that your "truncated" values all happen to have the exact same number of characters as the word "missing" from the format you might realize that the default length for that format is 7 characters because that is the only value it displays. You can either specify an explicit default length in the format definition or try applying the format with a specific width such as :format variable $idname11.;

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!

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
  • 3 replies
  • 1614 views
  • 1 like
  • 4 in conversation