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

Hello,

 

I have a table such as

ID           Sales     Year     Sales_classification

1             12         2008              4567

1              11        2008               7890

1              13        2008               5678

1              14        2009               4567

1              15        2009               7890

1               16       2009               5678

2                8       2008               4567

2              1        2008               7890

2              3        2008               5678

2              4        2009               4567

2              5        2009               7890

2               6       2009               5678

 

Condition includes:

IF

With the same ID

With the same YEAR

Sales_classification first digit larger than 6

 

THEN

sum the SALES meet all the conditions above

 

This may be done with or without CONDITION proc, there may be several ways and logic to do this.

Would you please help me with it?

 

Thank you very much!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Then switch to:

 

proc sql;
create table want as
select 
    ID, 
    year, 
    sum(case when first(cats(Sales_classification)) > "6" 
        then Sales 
        else 0 end) as sumSales
from have
group by id, year;
quit;
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

You could do:

 

proc sql;
create table want as
select ID, year, sum(Sales) as sumSales
from have
where first(cats(Sales_classification)) > "6"
group by id, year;
quit;
PG
yanshuai
Quartz | Level 8

OMG

You are awesome! It exactly does what I want. It is so neat and clean.

 

But the outcome table only shows the observation meet the condition. What if I also want those obs show "0" if do not meet the condition?

PGStats
Opal | Level 21

Then switch to:

 

proc sql;
create table want as
select 
    ID, 
    year, 
    sum(case when first(cats(Sales_classification)) > "6" 
        then Sales 
        else 0 end) as sumSales
from have
group by id, year;
quit;
PG
yanshuai
Quartz | Level 8

Great!

 

Thank you!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 5244 views
  • 1 like
  • 2 in conversation