BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Sounds easy, but I am not actually trying to replace the missing values with zeroes in a single column... I have some 250 columns representing fish species which I do not want to work on individually.

EG 4.1 can change column values in the query menu fairly easily, but I haven't found a way to automate this for all columns.

The Update statement in proc SQL can also easily change the missing values, but one variable at a time.

My question is: is it possible to batch proccess an entire dataset for this task? With some loop or special reference?

Thanks for your help!
6 REPLIES 6
Cynthia_sas
SAS Super FREQ
Marc:
Run this test program and see if it does what you want. It uses sashelp.class -- so you should be able to run it. You really only care about the array technique used in the second Data step program, but I needed to make up some missing data to test the program.
cynthia

[pre]
** make some data with missing values;
data newclass;
set sashelp.class;
if age = 13 then height = .;
else if age = 12 then weight = .;
else if age = 15 then do;
height = .;
weight = .;
end;
run;

proc print data=newclass;
title 'should have some missing';
run;

** For every observations, treat the numeric vars as though;
** they are in an array and use a do loop to set missing;
** to 0;
data fixmiss;
drop i;
set newclass;
array fix(*) _numeric_;
do i = 1 to dim(fix);
fix(i) = sum(fix(i),0);
end;
run;

proc print data=fixmiss;
title 'missing should be fixed';
run;
[/pre]
deleted_user
Not applicable
That worked great!

Many thanks!

Marc
deleted_user
Not applicable
Does anybody know if there any way to replace the missing values with zeroes for many columns WITHOUT USING A DATA STEP?
Thanks
prholland
Fluorite | Level 6
Try:
OPTIONS MISSING = '0';

This doesn't change the missing values, but displays them as '0'.

........Phil Holland
Siva_economist
Calcite | Level 5
Is it possible to replace the missing values with zeroes only on variables ending with "_q" ?
Thanks in advance.
RichardH_sas
SAS Employee
SAS data step code makes it easy to reference name prefix lists (e.g. all variables starting with q_) but unfortunately not what you're describing with a common suffix. In order to do that, I would write some SAS code to create a list of variable names as the value for a macro variable, then reference that macro variable in data step code similar to what Cynthia showed above.

Run the following code, then use the final data step shown by Cynthia. However, in that code, replace _numeric_ on the ARRAY statement with &qlist (the name of the macro variable we created). That should do the trick.

/* Create test data set */
data work.test1;
set sashelp.class;
if mod(_N_,2) = 1 then height=.;
/* Every second height missing */
if mod(_N_,5) = 1 then age=.;
/* Every fifth age missing */
rename height=height_q age=age_q;
run;

proc sql noprint;
select name
into : qlist separated by ", "
from dictionary.columns
where libname="WORK"
and memname="TEST1"
and upcase(name) like '%_Q';
quit;

%put &qlist;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1564 views
  • 1 like
  • 5 in conversation