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
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?
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;
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;
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.