DATA Step, Macro, Functions and more

Help in Proc SQL

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 91
Accepted Solution

Help in Proc SQL

 

I am trying to get the output like below in Proc SQL instead of using first. and last.variable

If any ID consists Y or N,  I only need Y all the time. 

 

ID     Product

1         Y

1         N

2         N

3         N

4        Y

4         N

 

Output:

ID      Product

1         Y

2         N

3          N

4         Y

 

 

Thanks for looking

 


Accepted Solutions
Solution
‎01-17-2018 09:40 AM
Super User
Posts: 9,611

Re: Help in Proc SQL

[ Edited ]
Posted in reply to Kalai2008

If you only need the largest of any number of values, use the max() summary function in SQL:

proc sql;
create table want as
  select id, max(product) as product
  from have
  group by id
;
quit;

Edit: gave the sum() variable the correct name

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎01-17-2018 09:40 AM
Super User
Posts: 9,611

Re: Help in Proc SQL

[ Edited ]
Posted in reply to Kalai2008

If you only need the largest of any number of values, use the max() summary function in SQL:

proc sql;
create table want as
  select id, max(product) as product
  from have
  group by id
;
quit;

Edit: gave the sum() variable the correct name

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 91

Re: Help in Proc SQL

Posted in reply to KurtBremser

Thank you...It worked.

☑ This topic is solved.

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

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