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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.