BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
machete
Calcite | Level 5

Hello

I am trying to calculate the sum of a variable per group when/conditional that another variable, venues=1

I tried the code below and does not net the correct resutls. I also tried using 'having'. Both having and where, keep in the produced table only those rows where venues=1.

I would like to have the sum for those where venues=1 but in this column (venuest1) also keep the rest of the rows in the dataset where venues ne 1, simply add them by = 0.

so the code in my opinion should include something of the type if venues=1 then do,  'else' venuest1=0

I am a beginnger in proc SQL so any suggestions how to solve this are more than welcome.

proc sql;

create table neo.regtest1 as

select * , sum(absvolume) as venuesT1

from neo.regtest

where venues=1

group by cptyname;

run;

Many thanks in advance!!

Neo

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Something like the following may work:

If it doesn't, post sample data and sample expected output.

proc sql;

create table neo.regtest1 as

select * , sum(absvolume*(venues=1)) as venuesT1

from neo.regtest

group by cptyname;

run;

View solution in original post

3 REPLIES 3
Reeza
Super User

Something like the following may work:

If it doesn't, post sample data and sample expected output.

proc sql;

create table neo.regtest1 as

select * , sum(absvolume*(venues=1)) as venuesT1

from neo.regtest

group by cptyname;

run;

machete
Calcite | Level 5

worked Smiley Happy thanks for the timely feedback

Marina
Calcite | Level 5

You need to include sample data, otherwise it is next to impossible to suggest anything helpful.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 801 views
  • 1 like
  • 3 in conversation