Good day everyone.
I am trying to run proc sql command and I am facing some difficulties
Background:
fatal represent numbers per case
countycode represent counties for each fatal.
I intend to generate a table that has unique countycodes and average fatal counts per county.
Below is my code
proc sql;
select fatals, countycode
from county
group by countycode
mean (fatals) as fatalcount;
quit;
I keep getting syntax errors.
I will appreciate help with this.
Thank you
Sir @PaigeMiller
Even the corrected code
proc sql;
select fatals, countycode, mean (fatals) as fatalcount
from county
group by countycode;
quit;
will cause SQL processor the computed mean here fatalcount merge back(remerge) with the original. Of course we are not aware of what OP's exact WANT but methinks we can make a guess from "I intend to generate a table that has unique countycodes ".
Therefore excluding fatals from the SELECT should get the desired result.
proc sql;
select countycode, mean (fatals) as fatalcount
from county
group by countycode;
quit;
proc sql;
select fatals, countycode, mean (fatals) as fatalcount
from county
group by countycode;
quit;
Sir @PaigeMiller
Even the corrected code
proc sql;
select fatals, countycode, mean (fatals) as fatalcount
from county
group by countycode;
quit;
will cause SQL processor the computed mean here fatalcount merge back(remerge) with the original. Of course we are not aware of what OP's exact WANT but methinks we can make a guess from "I intend to generate a table that has unique countycodes ".
Therefore excluding fatals from the SELECT should get the desired result.
proc sql;
select countycode, mean (fatals) as fatalcount
from county
group by countycode;
quit;
Thank you.
This worked.
And I generated unique ID.
Thank you
Thank you.
I understand why I keep seeing the syntax error.
Although I did not get a unique ID though.
Thank you
FYI - the majority of SQL is the same across all languages and most tutorials will work with SAS as well.
Here's the w3 tutorials:
https://www.w3schools.com/sql/default.asp
And the SQL library in the documentation has many good examples:
See the side bar for other common usage cases.
Thank you for the link.
Very helpful.
Thanks for the information.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.