@chennupriya wrote:
I wanted to check how do i apply the code to check percentage missing of all variables by Category A Category B and Category C
The first step in any macro writing ought to be to create working SAS code without macros and without macro variables, for a single data set. Once you have done that, turning the results into a macro will be relatively simple. But it doesn't appear you have done that yet.
It is easy for PROC SQL.
Make a macro to make the following code streamline .
data have;
set sashelp.heart;
if ranuni(1) < 0.2 then call missing(AgeAtStart,status);
run;
proc sql;
create table want as
select sex,
nmiss(AgeAtStart)/count(*) as nmiss_per_AgeAtStart,
nmiss(status)/count(*) as nmiss_per_status,
nmiss(height)/count(*) as nmiss_per_height
from have
group by sex;
quit;
It seems silly to use NMISS() with only one variable. That is what MISSING() is for. But it won't actually do what you want since either is just going to operate on each observation and not aggregrate.
Instead just use the COUNT() function of SQL. It will not count the missing values of the variable given.
,count(AgeAtStart)/count(*) as AgeAtStart
,count(status)/count(*) as status
,count(height)/count(*) as height
Plus that way the code should easier for SAS to push into a remote database.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.