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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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