I'm trying to get rid of negative dollar amounts in my data. For ex:
id cost eventDate
741 -$241.00 2021-10-21
741 $241.00 2021-10-21
741 $241.00 2021-11-20
I want to sum by ID and by date so that it looks like this:
id cost eventDate
741 $0 2021-10-21
741 $241.00 2021-11-20
proc sql;
create table claims
as select
memberNo,
planPayer,
claimHeaderId,
rollupeventid,
cpt,
cptdescription,
icd,
icdDescription,
cost,
eventDate,
eventid,
providerNPI,
providerName,
providerSpecialty
from xx.eventLineDetails
where providerSpecialty = 'Dermatology'
and eventDate between "2020-12-01" and "2021-12-31"
and claimatRisk=1
and planPayer not in ('C')
and cpt like ('J%');
quit;
Do you simply want to delete observations with a begative dollar amount? You example seems more like you want to sum the amounts grouped by ID and EventDate?
Please be more specific.
Then do
data have;
input id cost :dollar8.2 eventDate :yymmdd10.;
format cost dollar8.2 eventDate yymmdd10.;
datalines;
741 -$241.00 2021-10-21
741 $241.00 2021-10-21
741 $241.00 2021-11-20
;
proc summary data = have nway;
class id eventDate;
var cost;
output out = want(drop = _:) sum =;
run;
Example data.
Example data.
Example data.
For building a sum, see my answer here:
But what are the many other variables in your SQL query? To really help you, we need example data (post it as a data step with datalines into a code box, do not skip this!!) and what you expect as a result out of that.
If you want to do a sum in SQL, all variables in the select must be
or you will get a "remerge", where the original observations are all kept and each receives the sum over the group.
So it is important to know the roles of all your other variables. If, say, they are constant for a memberno and/or eventdate, then you need to include them all in the GROUP BY. If not, you need to decide which values for a given memberno/eventdate should take precedence in the result.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.