# Reading only selected columns from .tab file

**URL:** <https://discuss.ampl.com/t/reading-only-selected-columns-from-tab-file/1133>\
**Category:** Support\
**Tags:** data\
**Created:** [June 25, 2024, 12:33am UTC](https://discuss.ampl.com/t/reading-only-selected-columns-from-tab-file/1133 "2024-06-25T00:33:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_M](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/chris_m/32/789_2.png) [@Chris\_M](https://discuss.ampl.com/u/Chris_M)\
**Post date:** [June 25, 2024, 12:33am UTC](https://discuss.ampl.com/t/reading-only-selected-columns-from-tab-file/1133/1 "2024-06-25T00:33:42Z")

</div>

I have an ampl.tab format file containing data that I am using for multiple models. As a result, there are some columns that are only relevant to some of the models. Is there a way to read this data in without needing to define the irrelevant parameters?

For example, this is what the file looks like:

```auto
ampl.tab 1 8
CELL_IDS tableVal suppressionCost suppressionVal lowerBound upperBound LPL UPL
IA 20 20 0 0 190 0 0
IIC 22 22 1 0 190 5 5
TB 101 101 0 0 190 0 0

```

And in one model I might have the declarations

```auto
set CELL_IDS;
param tableVal {CELL_IDS};
param lowerBound {CELL_IDS};
param upperBound {CELL_IDS};

```

while the other has

```auto
set CELL_IDS;
param tableVal {CELL_IDS};
param suppressionVal {CELL_IDS};
param suppressionCost {CELL_IDS};
param LPL {CELL_IDS};
param UPL {CELL_IDS};

```

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [June 26, 2024, 4:23pm UTC](https://discuss.ampl.com/t/reading-only-selected-columns-from-tab-file/1133/2 "2024-06-26T16:23:23Z")

</div>

You can use a different table statement for each model, listing only the columns that you want to read. For example, to read data for the first model, you can define

```auto
table data1 IN "alldata.tab": 
   CELL_IDS <- [CELL_IDS], tableVal, lowerBound, upperBound;

```

Then `read` `table` `data1` will read only the columns `tableVal`, `lowerBound`, and `upperBound` from `alldata.tab`. The columns not listed in the table statement will be ignored, and you will not need to define parameters corresponding to those columns.

---

<div class="post-metadata">

**Author:** ![Chris\_M](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/chris_m/32/789_2.png) [@Chris\_M](https://discuss.ampl.com/u/Chris_M)\
**Post date:** [July 31, 2024, 1:04am UTC](https://discuss.ampl.com/t/reading-only-selected-columns-from-tab-file/1133/3 "2024-07-31T01:04:35Z")

</div>

Thank you so much! I thought I had tried that, but I must have gotten the syntax wrong the first time around. It works perfectly well now.
