Help using Base SAS procedures

Select from select query

Reply
Contributor
Posts: 28

Select from select query

Hi,

Is this possible to run a query from already written query like

select distinct salary from (select user_id, sum(salary) from emp where month =3 group by user_id) ;

this is an example so consider we are having 10 different sum of salary ...but i want to figure that out from select * from select query ....

Thanks for reverting back ..

Esteemed Advisor
Posts: 6,270

Re: Select from select query

Yes, you can do nested queries.

If you want to continue work on a query that is already definied, save it into a table by using create table ... as select ...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Esteemed Advisor
Posts: 6,977

Re: Select from select query

Yes, you can do that no problem, its called a subquery when another one is nestled in brackets.  I would however wonder why you are doing it like that, there are times to use subqueries, however from what you have said and posted, I don't think this is one of them.  Perhaps post some test data and required output.  Just from what you have posted, assuming it is differing months then:

select user_id, sum(salary) from emp group by month,user_id

rather than several queries.  Also note that distinct salary may return more than one row from your query, so how will handle that?

Contributor
Posts: 28

Re: Select from select query

Yes RW9@ & KurtBremser... i agree there are multiple ways but couldn't bring them that time so used that..

actually i used earlier select a,b from (select id ,cat from T 1 where some condition) aliasname....as i forgot to put this alias name so it makes me to put question  here on discussion portal ...but thanks for the effrort you guys put ..i appreciate it .thanks..

Ask a Question
Discussion stats
  • 3 replies
  • 459 views
  • 0 likes
  • 3 in conversation