how to sum all numeric variables in sashelp.class write do loop in sql
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
SQL server is not the same as SAS.
Let SAS do the heavy work and then push the results to the SQL server.
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
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.