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;
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.
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 = .;
?
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;
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.
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
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.