DATA Step, Macro, Functions and more

Calculation by Dates in SQL

Accepted Solution Solved
Reply
Contributor afs
Contributor
Posts: 28
Accepted Solution

Calculation by Dates in SQL

The Sold tables having variable.

 

                                            Alphabetic List of Variables and Attributes

 

                              #    Variable    Type    Len    Format       Label

 

                              4    ShipDay     Num        8    WeekDAY.        Day of the Week of Shipment

                              3    dates         Num        8    MMDDYY10.    Date accessory(s) shipped      

                              1   orders        Num        8                             Number of Order           

                              2    quantity      Num       8                            Quantity                  

                             

 

I want to display table containing 3 variables summarizing by year,  the total number of accessories sold each month;

 

proc sql;
select year(datepart(dates)) as A_Year, month(datepart(dates)) as A_Month , sum(quantity) as TTL_Accessories
from Sold
group by calculated S_Year,
quit;

 

I am getting log error as 

ERROR: The following columns were not found in the contributing tables: quit.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
97
98 NOTE: The SAS System stopped processing this step because of errors.


Accepted Solutions
Solution
‎11-28-2016 01:54 AM
Respected Advisor
Posts: 3,893

Re: Calculation by Dates in SQL

[ Edited ]

ERROR: The following columns were not found in the contributing tables: quit.

 

If you get such weird error messages then always ask yourself what the heck could trigger SAS to get so confused.

Very often such errors are the result of a forgotten semicolon - and as you do have a comma instead of a semicolon the SAS compiler believes the "quit" is still part of your group by statement and therefore must be a variable.

 

BTW:

If you also create a Month variable then you'll get 12 rows per year but if you only group by year then all 12 rows in the same year will have the same sum. If you want montly sums then you need to add the month to the group by clause.

View solution in original post


All Replies
Solution
‎11-28-2016 01:54 AM
Respected Advisor
Posts: 3,893

Re: Calculation by Dates in SQL

[ Edited ]

ERROR: The following columns were not found in the contributing tables: quit.

 

If you get such weird error messages then always ask yourself what the heck could trigger SAS to get so confused.

Very often such errors are the result of a forgotten semicolon - and as you do have a comma instead of a semicolon the SAS compiler believes the "quit" is still part of your group by statement and therefore must be a variable.

 

BTW:

If you also create a Month variable then you'll get 12 rows per year but if you only group by year then all 12 rows in the same year will have the same sum. If you want montly sums then you need to add the month to the group by clause.

Contributor afs
Contributor
Posts: 28

Re: Calculation by Dates in SQL

Noted. I made the changes and it worked . Thanks
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 161 views
  • 0 likes
  • 2 in conversation