Hello,
I am not sure how to do what I want. Basically I have a group variable of organizations I am interested in, I would like to look across the data set see how many variables are empty for each organization.
So like data I have:
ORG | Var1 | Var2 | Var3 |
OrgA | . | 1 | 0 |
OrgB | 1 | 1 | 0 |
OrgC | . | . | . |
Want:
ORG | Count of Missing Var |
OrgA | 1 |
OrgB | 0 |
OrgC | 3 |
I have about 40 organizations in the group variable and about 200 variables total.
Thanks in advance!
data want; set have Countofmissing= cmiss(Var1, var2, var3); run;
should do it.
If you have lots more variables there may be ways to shorten the syntax with variable lists but we would have to see a more complete description of your data.
data want; set have Countofmissing= cmiss(Var1, var2, var3); run;
should do it.
If you have lots more variables there may be ways to shorten the syntax with variable lists but we would have to see a more complete description of your data.
I do have a lot more variables, I need to look at them all. What info do you think we need?
I tried
proc sort data = Have; by Org; run;
data want;
set Have;
Countofmissing= cmiss(Var1-Var200);
by Org;
run;
But it did not work, the new Countofmissing wasnt counting. They were all equal to 1.
@AJYass wrote:
I do have a lot more variables, I need to look at them all. What info do you think we need?
I tried
proc sort data = Have; by Org; run;
data want;
set Have;
Countofmissing= cmiss(Var1-Var200);
by Org;
run;
But it did not work, the new Countofmissing wasnt counting. They were all equal to 1.
You subtracted variable Var200 from Var1.
Use : cmiss( OF var1-var200);
or if all of your variables are actually named like that
cmiss (of var:)
the : is a list builder that says "use all the variables whose names start with VAR (or whatever characters you supply).
OH! Okay thanks for point that out.
They are all uniquely named variables unfortunately.
The first is A1_1 and the final is Vstatus so the code should be
data want;
set have;
Countofmissing= cmiss(OF A1_1-Vstatus);
run;
Is that correct? Thanks so much for all the help!
If you use a list like "of thisvar -- thatvar" , note there are 2 dashes, then SAS uses the variable positions to build the list and gets all of the variables starting at thisvar and ending at thatvar.
@AJYass wrote:
OH! Okay thanks for point that out.
They are all uniquely named variables unfortunately.The first is A1_1 and the final is Vstatus so the code should be
data want;
set have;
Countofmissing= cmiss(OF A1_1-Vstatus);
run;
Is that correct? Thanks so much for all the help!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.