SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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 = .;

?

robertrao
Quartz | Level 8

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;

Kurt_Bremser
Super User

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.

robertrao
Quartz | Level 8

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

Kurt_Bremser
Super User

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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1662 views
  • 0 likes
  • 2 in conversation