SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

how to sum all numeric variables in sashelp.class write do loop in sql 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

SQL server is not the same as SAS.

Let SAS do the heavy work and then push the results to the SQL server.

 

Cynthia_sas
SAS Super FREQ

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:

no_do_loop_needed.png

 

  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

s_lassen
Meteorite | Level 14

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.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 3930 views
  • 1 like
  • 5 in conversation