Greetings all,
I have the following data set with some missing values. When I try to convert them into 0, however, most of them do not show up. How could I fix this issue?
data testing;
infile datalines missover dlm=',';
input id $ visits unitpurchased @;
if unitpurchased=. then unitpurchased=0;
do while (unitpurchased ^=.);
output;
input unitpurchased @;
end;
drop visits;
datalines;
C005,3,15,,39
D2356,4,11,,,5
A323,3,10,15,20
F123,1,
run;
Since visits contains the number of following columns, do this:
data testing;
infile datalines missover dlm=',' dsd;
input id $ visits @;
do i = 1 to visits;
input unitpurchased @;
if unitpurchased = . then unitpurchased = 0;
output;
end;
drop visits i;
datalines;
C005,3,15,,39
D2356,4,11,,,5
A323,3,10,15,20
F123,1,
run;
Edit: added the dsd option.
Before executing the code use
options missing=0;
options missing=0;
data testing;
infile datalines missover dlm=',';
input id $ visits unitpurchased @;
datalines;
C005,3,15,,39
D2356,4,11,,,5
A323,3,10,15,20
F123,1,
run;
Since visits contains the number of following columns, do this:
data testing;
infile datalines missover dlm=',' dsd;
input id $ visits @;
do i = 1 to visits;
input unitpurchased @;
if unitpurchased = . then unitpurchased = 0;
output;
end;
drop visits i;
datalines;
C005,3,15,,39
D2356,4,11,,,5
A323,3,10,15,20
F123,1,
run;
Edit: added the dsd option.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.