- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
how to sum all numeric variables in sashelp.class write do loop in sql
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why do you want to limit yourself to SQL? There are other procedures better suited for the job. Check out Proc Means or Proc Summary
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
SQL server is not the same as SAS.
Let SAS do the heavy work and then push the results to the SQL server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
SAS Procedures like PROC MEANS and PROC TABULATE (and others) support the use of _NUMERIC_ and _CHARACTER_ to deal with all the numeric or all the character variables. I do not believe you can use this syntax shortcut in PROC SQL.
Using SAS procedures you don't need a do loop at all:
And PROC REPORT would do this too. But I would probably start with PROC MEANS.
Using SQL, you don't need a do loop, but you do need to know the names of the variables:
proc sql;
select sum(age) as agesum, sum(height) as htsum, sum(weight) as wtsum
from sashelp.class;
quit;
Hope this helps,
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think @Cynthia_sas already gave you a good answer, but you should also know that there is no such thing as a "do loop" in SQL. This is because SQL is a declarative language (you tell the computer what you want), rather than a procedural language (you tell the computer what to do) like SAS datastep or macro language.