BookmarkSubscribeRSS Feed
EloarL
Obsidian | Level 7

HELLO, SOMEONE WOULD KNOW HOW I CAN REPLACE VALUES '.' EXISTING ON A SAS TABLE FOR 0?

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

If what you're asking is how to replace missing numerical values (.) with zero, then do

 

data have;
input ID$ var1 var2 var3;
datalines;
1 . 3 4 
2 2 0 .
3 . . 3
4 . 8 .
5 5 . .
;

proc stdize data=have out=want reponly missing=0;
run;
novinosrin
Tourmaline | Level 20

Hi could you post an sample of what your dataset contains. i.e a sample input & sample output(requirement)

EloarL
Obsidian | Level 7

MY INPUT BASE CONTAINS VALUES (.) AS BELOW WITH 50 ROWS AND 754 COLUMNS. MY OUTPUT BASE WILL BE EVEN WITH VALUES (.) REPLACED BY 0. THE DOUBT IS HOW TO MAKE THIS REPLACEMENT ON ALL COLUMNS CONTAINING (.)
COLUMN 1 COLUMN2  COLUMN3....COLUMN754
INDUST            .                -0.0660               .

      .....

 

novinosrin
Tourmaline | Level 20

Hi @EloarL   Thank you. Did you try the solution given by @PeterClemmensen ? 

ballardw
Super User

@EloarL wrote:

MY INPUT BASE CONTAINS VALUES (.) AS BELOW WITH 50 ROWS AND 754 COLUMNS. MY OUTPUT BASE WILL BE EVEN WITH VALUES (.) REPLACED BY 0. THE DOUBT IS HOW TO MAKE THIS REPLACEMENT ON ALL COLUMNS CONTAINING (.)
COLUMN 1 COLUMN2  COLUMN3....COLUMN754
INDUST            .                -0.0660               .

      .....

 


Please do not use all capitol letters in posts. It is hard to read and considered to be shouting.

 

The question is do you want to actually change missing to zero for calculations OR for displaying 0 optionally instead of the default period character for missing values?

 

If you want to display 0 instead of missing in a report, proc print or similar output then setting the system missing option may be what you want:

 

data junk;
   x=25;
   y=.;
run;
options missing='0';
proc print;
run;

will Display the missing value for the y variable as 0.

You can use any single character as the missing value as desired.

It will stay in affect until you change the option with another Options missing assignment.

 

If want to change the actual value to 0 then you will need to use data step code or other transformations.

 

A third option would be create one or more custom formats for the variables that will display 0 instead of . for missing.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 6 replies
  • 837 views
  • 1 like
  • 5 in conversation