Can we use where and having clauses in a single SAS program.
ex: proc sql;
select a,b,c from test
where state in 'KA'
and having <some condition>.
Is the above program run correctly, if not why ?
Answers were Sorted based on User's Feedback
Answer / rauthu
Yes, WHERE and HAVING can be used in single program. HAVING must be after GROUP by clause.
Example:
proc sql;
select make, model, avg(msrp) as avgmsrp, msrp
from sashelp.cars
where make ='Honda'
group by model
having avgmsrp < 100000;
quit;
Is This Answer Correct ? | 9 Yes | 1 No |
Answer / rajasekaran
having statement should mentioned after group by statement only
proc sql;
select a,b,c from test
where state in 'KA'
group by xyz
and having <some condition>.
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / a.k.naidu
Having clause can be used only with 'group by'. Difference between 'where' and 'having' is that former works on variable level and latter works on observation level. 'having' works like second where condition on "grouped data"
Is This Answer Correct ? | 2 Yes | 0 No |
Diff between proc sql merge and join?
What is the maximum length of the macro variable? : sas-macro
What is the difference between reading data from an external file and reading data from an existing data set?
What is a pdv and what are its functions?
If reading an external file to produce an external file, what is the shortcut to write that record without coding every single variable on the record?
how to delete the duplicate columns permanently in SQL
What statement do you code to tell SAS that it is to write to an external file? What statement do you code to write the record to the file?
If you’re not wanting any SAS output from a data step, how would you code the data statement to prevent SAS from producing a set?
Where do the database management systems store data and how do u import them.
How will you assign all the variables of an dataset into a macro variable separated by a space? For example if a dataset has variables A,B,C. Assign them to a macro variable X as X=A B C
what is PhaseIII, ODS, TLG, Macro and Proc in SAS
How do dates work in sas?