Quartz | Level 8

## Count

I am having variables stage wise. For example stage 1, stage2 and stage 3. It consist of values 0 and 1. If we assume for 10 applicants then how to count the no. of applicants in stage 1, like wise stage 2 and 3. Want to show each stage count.

Appli no  stage1 stage2 stage3

1               0          1          1

2               1          0         0

3

4

5

6

7

8

9

10

I have done :

if stage1>0 then

return 1

else return 0

1 ACCEPTED SOLUTION

Accepted Solutions
Rhodochrosite | Level 12

## Re: Count

One way could be to have three different objects, one for each stage. The objects show the sum of stage1, stage2 and stage3.
You can add labels and text to each object to tell what stage is shown.
I don't really understand why you need to create a hierarchy, could it not be done just graphically?

//Fredrik
15 REPLIES 15
Garnet | Level 18

## Re: Count

What output are you expecting from your code?

What do you mean by "return 1" ? - is it per row or per the whole data?

what variable should hold the result?

Quartz | Level 8

## Re: Count

I want the total count of each stage and I will be creatiNg the hierarchy of the stages.
Garnet | Level 18

## Re: Count

Alternative to @Patrick's solution you can use proc summary  or proc means and some other procedures:

``````proc summary data=have <missing noprint>; * the last are optional;
class appli_no;  /* or just class; for final total */
var stage1-stage3;
output out=result sum=;
run;``````
Quartz | Level 8

## Re: Count

I need total count of the variable.
Opal | Level 21

## Re: Count

Providing a SAS data step creating the full sample data and showing the desired result would help.

Proc Summary might be what you're really after but given your a bit underspecified question here one way to go.

``````data have;
input Appli_no stage1 stage2 stage3;
datalines;
1 0 1 1
2 1 0 0
3 0 0 1
;

data want;
set have end=last;
retain s1 s2 s3;
s1+stage1;
s2+stage2;
s3+stage3;
if last then output;
keep s1 s2 s3;
run;
``````

Quartz | Level 8

## Re: Count

Can we directly in VA?
Rhodochrosite | Level 12

## Re: Count

For sure.

add a dummy variable, like scope="all".

then use stageX variables as numeric variables with sum as aggregation.

have a list item with the scope variable and the stageX variables.

this should work for you.

Quartz | Level 8

## Re: Count

I am already haviNg stages variables in numeric. But when I convert that to category to create hierarchy , does it effect result or count..
Quartz | Level 8

## Re: Count

Can we directly in VA? I want to create hierarchy and having different stages data and custom category of the stages also. Each stage having the values 0 and 1. But I want to take only one which signifies completed.
Tourmaline | Level 20

## Re: Count

I don't know all in's and out's of VA, but sponanously I think your data should be restructured so it can handle more dynamic requets.

a tronspose so you'll have:

``````Appli_no Stage
1             2
1             3
2             1

``````

I see no immediately need to fill in stages with 0, but that depends what a 0 means in your original data. If you need it just an extra columns with 0/1.

Data never sleeps
Quartz | Level 8

## Re: Count

1 means completed.
Tourmaline | Level 20

## Re: Count

But what does 0 mean?
Have been enrolled and not completed, or perhaps not even enrolled?
Data never sleeps
Quartz | Level 8

## Re: Count

Actually I just want the count of 1 which means completed. 0 means not completed but I don't want that.
Rhodochrosite | Level 12

## Re: Count

One way could be to have three different objects, one for each stage. The objects show the sum of stage1, stage2 and stage3.
You can add labels and text to each object to tell what stage is shown.
I don't really understand why you need to create a hierarchy, could it not be done just graphically?

//Fredrik
Discussion stats
• 15 replies
• 817 views
• 7 likes
• 6 in conversation