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

Hi all, 

I have a quick simple question.

 

data have;

input Id a b  ;

1 2  2

1 2  2

1 3  2

2 4  .

2 4  .

;

run;

 

Proc sql; 

Create table want as Id, a, sum(b) as new from have group by ID, a; quit;

 

This code does not account for the missing B. it means in "want table" it does not give the ID2.

If I merge the want table with the "have table'  my problem will solve. However, I was wonder if I can count for the missing directly in this code. So the data have should be like below:

 

data want;

input Id a new  ;

1 2  4

1 3  2

2 4  .

;

run;

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

As far as I can see this gives you the "WANT" result you want:

 

Proc sql; 
Create table want as 
select Id, a, sum(b) as new 
from have 
group by ID, a; 
quit;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

As far as I can see this gives you the "WANT" result you want:

 

Proc sql; 
Create table want as 
select Id, a, sum(b) as new 
from have 
group by ID, a; 
quit;
ali_far
Obsidian | Level 7
Thanks for your reply.

I just tested the code here and it works for my sample data! You are right..
However, dont know why it does work ( I mean the way I want) for my real data..

I need to recheck other things perhaps...

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 539 views
  • 0 likes
  • 2 in conversation