SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AJYass
Calcite | Level 5

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:

ORGVar1 Var2 Var3
OrgA.10
OrgB110
OrgC...

 

Want:

ORGCount of Missing Var
OrgA1
OrgB0
OrgC3

 

I have about 40 organizations in the group variable and about 200 variables total.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
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.

View solution in original post

5 REPLIES 5
ballardw
Super User
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.

AJYass
Calcite | Level 5

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.

ballardw
Super User

@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).

 

AJYass
Calcite | Level 5

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!

ballardw
Super User

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!


 

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 977 views
  • 0 likes
  • 2 in conversation