SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

count of variable with condition

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

count of variable with condition

Dear all,

 

I have a data set which looks like in the attached file, and I need the output file as in the attached (other small table). I have tries using many ways but could not get the expected output.

 

 

Kindly help.

 

 

Thank you!


Accepted Solutions
Solution
‎03-09-2016 01:34 AM
Trusted Advisor
Posts: 1,137

Re: count of variable with condition

[ Edited ]

please try

 

proc sort data=have;
by manager date;
run;

data want;
set have;
by manager date;
retain count tot;
if first.date then do;
count=1;
tot=total;
end;
else do;
count=count+1;
tot=tot+total;
end;
if last.date;
drop staff total;
run;

 

alternatively by proc sql

 

proc sql;
create table want as select manager, date, count(staff) as count, sum(total) as tot from have
group by manager,date;
quit;
Thanks,
Jag

View solution in original post


All Replies
Solution
‎03-09-2016 01:34 AM
Trusted Advisor
Posts: 1,137

Re: count of variable with condition

[ Edited ]

please try

 

proc sort data=have;
by manager date;
run;

data want;
set have;
by manager date;
retain count tot;
if first.date then do;
count=1;
tot=total;
end;
else do;
count=count+1;
tot=tot+total;
end;
if last.date;
drop staff total;
run;

 

alternatively by proc sql

 

proc sql;
create table want as select manager, date, count(staff) as count, sum(total) as tot from have
group by manager,date;
quit;
Thanks,
Jag
Contributor
Posts: 24

Re: count of variable with condition

Thank you so much Jagadish.. Smiley Happy
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 545 views
  • 1 like
  • 2 in conversation