DATA Step, Macro, Functions and more

Specific Table creation by properties matching

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Specific Table creation by properties matching

Hello.

I have two tables. 1st order is 61312*2 (two columns i.e. origin and destination, values ranges from 1 to 81 in both columns).

2nd table is 81*81 (include length between origin and destination)

Now I need to create a table having order 61312*3 i.e origin*destination*length, i.e. to write a code which take the value from 2nd matrix (length) for their respective values in 1st matrix.

Kindly let me know how should I proceed.


Accepted Solutions
Solution
‎07-06-2014 08:32 AM
Super User
Super User
Posts: 7,071

Re: Specific Table creation by properties matching

Posted in reply to fayyazcivil

You can either add the aliases that I left out to the FROM clause

from have A  left join lookup B

or just use the table names as the aliases.

select HAVE.*,LOOKUP.length

View solution in original post


All Replies
Super User
Super User
Posts: 7,071

Re: Specific Table creation by properties matching

Posted in reply to fayyazcivil

Assume your first table is named HAVE and your second in named MATRIX.  You need to convert the second so that it is has the ORIGIN and DESTINATION as actual variables instead of row# or col#.  Then just can just merge the two tables.


data lookup ;

   set matrix;

   array val _numeric_;

  origin = _n_;

    do destination = 1 to 81 ;

   length = val(destination);

      output;

   end;

run;

proc sql ;

create table want as select a.*,b.length

    from have left join lookup

    on a.origin = b.origin

    and a.destination = b.destination

;

quit;

Occasional Contributor
Posts: 14

Re: Specific Table creation by properties matching

Dear Tom, thank you very much for this.

As you said the second table name Matrix, how can I define the Input variable in this case, i.e. origin1-origin81??

Super User
Super User
Posts: 7,071

Re: Specific Table creation by properties matching

Posted in reply to fayyazcivil

Not sure I understand the question. How to input the data depends on the form that the data is currently in.  If you have it in a CSV file with 81 lines of 81 numbers then this program will read it into the a table with three columns and 81x81 rows.

data lookup ;

  infile 'matrix.csv' dsd truncover length=2000 ;

  origin+1;

  do destination=1 to 81 ;

    input length @;

    output;

  end;

run;

Occasional Contributor
Posts: 14

Re: Specific Table creation by properties matching

Dear Tom,

Yes, the above coding has worked well. Now the problem is when I run it with proc sql, the following error occurs:

415  proc sql ;

416  create table want as select a.*,b.length

417      from have left join lookup

418      on a.origin = b.origin

419      and a.destination = b.destination

420  ;

ERROR: Unresolved reference to table/correlation name a.

ERROR: Unresolved reference to table/correlation name b.

ERROR: Unresolved reference to table/correlation name a.

ERROR: Unresolved reference to table/correlation name b.

ERROR: Could not expand a.*, correlation name not found.

ERROR: Unresolved reference to table/correlation name b.

ERROR: The following columns were not found in the contributing tables: a.

421  quit;

Solution
‎07-06-2014 08:32 AM
Super User
Super User
Posts: 7,071

Re: Specific Table creation by properties matching

Posted in reply to fayyazcivil

You can either add the aliases that I left out to the FROM clause

from have A  left join lookup B

or just use the table names as the aliases.

select HAVE.*,LOOKUP.length

Occasional Contributor
Posts: 14

Re: Specific Table creation by properties matching

Perfect! . Thank you very much

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1114 views
  • 6 likes
  • 2 in conversation