Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same variable name in 2 programs

Status
Not open for further replies.

mikeymay

Programmer
May 2, 2007
10
GB
I have 2 programs that have pretty much the same sets of code in each one, but each one uses to different tables/datasets to perform the same calculations.

There is a point in each set of programs where they need to pull a resulting variable from a table/dataset from the other program, but this/these variables have the same variable name.

Is there a way of referencing the variables buy table/dataset name and variable name, e.g.

Table1 = Table/dataset
Table2 = Table/dataset
Var = Variable appearing in both Table1 & Table2

NewVar = Table1.Var + Table2.Var


Thanks
 
In the SAS datastep each variable in the datastep must be unique. Therefore when you need the same varname from another table most of us would rename one of the variables.

That stated, you can use the PROC SQL using the method you lay out. Have your programs run to completion, then use proc SQL to join the table in question using the alias feature. Here is an example. I have my final value 'FINALVAL' in table MAIN and MAIN2.

Code:
proc sql;
  create table myresults as
  select (a.finalval + b.finalval) as myfinalval
  from main as a
  left join main2 as b
  /* IF YOU NEED THESE STATEMENTS 
   ON
   WHERE
  */
  ;
  quit;

Hope this helps you.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top