- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hello,
I have a numeric field called DAYSTOADMIT(contains values like 0, 1 ,33, 24 etc etc)
I am trying to apply formats to assign 1 to those that have a missing value by assigning them a value of 1 so i can summarize later using tabulate.
.
I used the following format and from the resultant dataset when i say "where DAYSTOADMIT ne 0" I AM GETTING 0 pulled up . It is surprising to me..
can someone explain why this is happening???
Proc format library=work;
invalue ADMIT
. = 1
other=0
;
run;
data want;
set have;
informat DAYSTOADMIT Admit.;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then do a datastep like this
data want (keep=c_all c_miss percentage);
set have end=done;
retain c_all 0 c_miss 0;
c_all + 1;
c_miss + (daystoadmit = .);
if done
then do;
percentage = c_miss / c_all;
put percentage percent8.2;
call symput('percentage',put(percentage,percent8.2));
call symput('percentage_r',put(percentage * 100,best.));
output;
end;
run;
%put &percentage;
%put &percentage_r;
You'll see te values in the log, you have them in a dataset and in macro variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Assigning a format or informat NEVER changes the value of a variable.
So the best option is
data want;
set have;
if daystoadmit = . then daystoadmit = 1;
run;
And why don't you simply use
where daystoadmit = .;
?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Kurt.
I think we need to use the following:Is that true when i want to get the total number of records later?
data want;
set have;
if daystoadmit = . then daystoadmit = 1; else daystoadmit =0;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you just want to know the number of missings, do
proc sql;
select count(*) from have where daystoadmit is missing;
quit;
Or use a proc freq on daystoadmit and extract the observation for missing.
So you don't have to change the value at all, and preserve the original information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks again. Actually I need to do more than that. I had the same thing posted a few days ago and i got good response/help.
i am doing the :
count of missing/Total records*100
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Then do a datastep like this
data want (keep=c_all c_miss percentage);
set have end=done;
retain c_all 0 c_miss 0;
c_all + 1;
c_miss + (daystoadmit = .);
if done
then do;
percentage = c_miss / c_all;
put percentage percent8.2;
call symput('percentage',put(percentage,percent8.2));
call symput('percentage_r',put(percentage * 100,best.));
output;
end;
run;
%put &percentage;
%put &percentage_r;
You'll see te values in the log, you have them in a dataset and in macro variables.