BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
oadeyemi
Obsidian | Level 7

 

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 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26
proc sql;
select fatals, countycode, mean (fatals) as fatalcount
	from county 
	group by countycode;
quit;
--
Paige Miller
novinosrin
Tourmaline | Level 20

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;
oadeyemi
Obsidian | Level 7

Thank you.

This worked.

And I generated unique ID.

Thank you

oadeyemi
Obsidian | Level 7

Thank you.

I understand why I keep seeing the syntax error.

Although I did not get a unique ID though.

Thank you

Reeza
Super User

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:

https://support.sas.com/documentation/cdl//en/sqlproc/69822/HTML/default/viewer.htm#p016wt256y0c2on1...

 

See the side bar for other common usage cases.

 

oadeyemi
Obsidian | Level 7

Thank you for the link.

Very helpful.

Thanks for the information.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2268 views
  • 0 likes
  • 4 in conversation