DATA Step, Macro, Functions and more

how to assign blanks for numeric variable

Accepted Solution Solved
Reply
Regular Contributor
Posts: 165
Accepted Solution

how to assign blanks for numeric variable

I have this sample of the variable which is the result of merging datasets 

I need to know how I can assign blanks for the value of 0 and . if the variables are numeric without mentioning the variables names 

I have too many variables and I don't want to do it by if statement for each variable individually

do you have suggestions?

 

this is my sample 

 

ESCGIOpen_GITOTAL_PACs_GIhptotal_cases1hp_pendingreview
.....
.....
.....
.....
005300
.....
.....
.....
.....
.....
001..
.....
.....
.....
.....
001..
.....
.....
002500
.....
001..
001..
001..
.....
.....
001..
.....
002..
.....
00400
00600
00200
00200
.....
00200
00200
00100
.....
00200
.....
001..
.....
.....
.....
212400
.....
001000
.....
.....
.....
.....
00100
00101
.....
.....
.....
.....
.....
.....

Accepted Solutions
Solution
‎04-25-2018 09:33 AM
Super User
Posts: 23,937

Re: how to assign blanks for numeric variable

Use a format.

 

proc format;
value my_cust_fmt
0, . =' '
other = [best8.];
run;

data have;
set sashelp.class;
if age in (12, 10) then call missing(age, height);

format _numeric_ my_cust_fmt.;
run;

View solution in original post


All Replies
PROC Star
Posts: 617

Re: how to assign blanks for numeric variable

[ Edited ]
data want;
set have;
array change_num _numeric_;
do over change_num;
if change_num=. then change_num=0;
end;
run;

Check this, will change all numeric with missing values to 0

 

Thanks,
Suryakiran
Super User
Posts: 5,914

Re: how to assign blanks for numeric variable

You can't assign a blank to a numerical column.
You can however chose to display missing values as a blank using the MISSING system option.
Data never sleeps
Super User
Posts: 6,899

Re: how to assign blanks for numeric variable

There is no such thing.  It is not possible for numeric variables to take on a value of blank.  The best you can do is this:

 

options missing=" ";

 

That causes missing values for numeric variables to be displayed as a blank when reporting.  But the value that is stored, and the value that you would refer to in your programming statements is still a dot not a blank.

 

If you wish, you can convert zero to a missing value:

 

if var = 0 then var = .;

 

After that, the missing= option would apply.  First, you have to decide whether changing zero to missing is actually destroying some of your information.

Regular Contributor
Posts: 165

Re: how to assign blanks for numeric variable

Posted in reply to Astounding

This is a good soln but I have to call each variable   if var = 0 then var = .;  which will consume time 

Solution
‎04-25-2018 09:33 AM
Super User
Posts: 23,937

Re: how to assign blanks for numeric variable

Use a format.

 

proc format;
value my_cust_fmt
0, . =' '
other = [best8.];
run;

data have;
set sashelp.class;
if age in (12, 10) then call missing(age, height);

format _numeric_ my_cust_fmt.;
run;
Regular Contributor
Posts: 165

Re: how to assign blanks for numeric variable

Thanks so much this is so efficient 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 150 views
  • 4 likes
  • 5 in conversation