BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
luvscandy27
Quartz | Level 8

Hello, 

After I transpose my data I am left with . for the fields that do not contain any information. Is it possible to add -- this to those fields instead of the .? And example of the data is attached. 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

 

The missing character is exactly that - ONE character. You can set that by using:

Options missing="x"; where x represents exactly one character.

If you want to display two or more characters that can be accomplished with a custom format (or formats) depending on how your remaining data is displayed.

An example:

proc format;
value missdash (default=12)
. = '--'
;
run;

data example;
   input x;
datalines;
1
2
568
.
23456667
;

proc print data=example;
   format x missdash.;
run;

The default=12 in the value statement is a good idea as this type of format, only supplying 2 characters for one value (the missing one) means the default length would be set to 2 and any larger than 99 value would get truncated and decimals very problematic.

 

Note that if you change the missing character with the option statement you still use the dot in code to indicate missing. The option only affects the DISPLAY of values.

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Show the example input data and how you transformed it.

What would you want the missing values to be represented by if not by a missing value?

ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

 

The missing character is exactly that - ONE character. You can set that by using:

Options missing="x"; where x represents exactly one character.

If you want to display two or more characters that can be accomplished with a custom format (or formats) depending on how your remaining data is displayed.

An example:

proc format;
value missdash (default=12)
. = '--'
;
run;

data example;
   input x;
datalines;
1
2
568
.
23456667
;

proc print data=example;
   format x missdash.;
run;

The default=12 in the value statement is a good idea as this type of format, only supplying 2 characters for one value (the missing one) means the default length would be set to 2 and any larger than 99 value would get truncated and decimals very problematic.

 

Note that if you change the missing character with the option statement you still use the dot in code to indicate missing. The option only affects the DISPLAY of values.

luvscandy27
Quartz | Level 8

Thank You!

ballardw
Super User

A small number of procedures, such as Proc tabulate will also allow you to specify missing text that could be more than a single character but if you aren't using such that may not help much.

 

Consider this contrived example where incomplete data has a U (for unknown perhaps) sex and missing value for age. All of the requested statistics of min , max and mean are missing but display optional text "Unk".

data example;
   input sex $ age;
datalines;
m  25
m  16
m  23
f  18 
f  19
f  20
u  .
;

proc tabulate data=example;
   class sex;
   var age;
   table sex,
         age*(max min mean)
         /misstext='Unk'
   ;
run;

The Format is often more flexible though.

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