BookmarkSubscribeRSS Feed
MustafaAbdelhaq
Calcite | Level 5

Hello,

So I have multiple tables with only one record in each one of them. I have another table which combines all the tables in one table.

What i'm trying to do is to calculate a value from multiple tables (subtract and add) to then create a new column with the result.

Your help is appreciated .

1 REPLY 1
PGStats
Opal | Level 21

You could use SASHELP.VTABLE and call execute to generate the SQL queries:

/* Create three example tables */

data table_A table_B table_C;

do x = 1,2,3; output; end;

run;

data _null_;

length oldTable newTable $41;

call execute("proc sql;");

do until (done);

     /* Get the table names */

    set sashelp.vtable(

        where=(libname="WORK" and memname like "TABLE_%")) end=done;

    oldTable = cats(libname, ".", memname);

     /* Create the new table name from the old one */

    newTable = cats(oldTable, "_new");

     /* Create the query with the definition of the new variable */

    call execute(catx(" ", "create table", newTable, "as select *, x+1 as y from", oldTable, ";"));

    end;

call execute("quit;");

stop;

run;

/* Execution of the SQL procedure will occur here */

PG

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 764 views
  • 1 like
  • 2 in conversation