Contributor
Posts: 44

# Table Combination

I have some tables that I really need to combine it together. I just want to keep momr = 1, momr=10, momr=99 for each table. And have additional column on the left side of momr, so I can put a name in.

All the tables are the same as follow:

 momr _NAME_ _ewret1__Average_ret _ewret1__CAPM_Alpha _ewret1__FF3_Alpha 1 param 1.09 0.21 0.15 1 T (6.22) (3.26) (3.08) 2 param 1.09 0.21 0.15 2 T (6.20) (3.46) (3.42) 3 param 1.00 0.13 0.07 3 T (5.83) (2.28) (1.71) 4 param 1.04 0.17 0.10 4 T (6.01) (2.79) (2.34) 5 param 0.97 0.07 -0.01 5 T (5.33) (1.05) (-0.32) 6 param 0.98 0.06 -0.03 6 T (5.05) (0.77) (-0.68) 7 param 0.90 -0.05 -0.16 7 T (4.30) (-0.58) (-2.98) 8 param 0.78 -0.21 -0.32 8 T (3.46) (-2.00) (-5.47) 9 param 0.67 -0.34 -0.48 9 T (2.77) (-2.78) (-6.66) 10 param 0.27 -0.77 -0.95 10 T (1.01) (-5.10) (-10.01) 99 param -0.83*** -0.98*** -1.10*** 99 T (-6.04) (-7.75) (-11.34)

I really appreciate if someone can help me with it.

Super User
Posts: 10,209

## Re: Table Combination

What name should be contained in your new variable?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 44

## Re: Table Combination

I mean it just like Jump for 1st table, IV for 2nd table

attachments. -##
Super User
Posts: 10,209

## Re: Table Combination

If you want those values automatically assigned in the data step, from where do you get them?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 44

## Re: Table Combination

I have 5 datasets that contain table (all tables have the same format),
then I try to combine these 5 datasets in one file.
Is this what you mean?

Thank you.

attachments. -##
Super User
Posts: 10,209

## Re: Table Combination

In your initial post, you wrote:

"And have additional column on the left side of momr, so I can put a name in."

What "name" do you want to have in this new column, and from where do you get it?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 44

## Re: Table Combination

The name of table is the name of file. So I am not sure if I can insert one
variable (column) and observation inside.

attachments. -##
Super User
Posts: 10,209

## Re: Table Combination

Let's make some clarifications:

- dataset: a SAS dataset; a member of a SAS library; represented physically as a .sas7bdat file in a directory for which a libname is assigned

- file: usually used for "external file", not a SAS dataset; often contains tabular data that can be imported into a SAS dataset

- observation: a single record (row) of a SAS dataset, consisting of one or more columns(variables)

- variable or column: a single piece of data within an observation; numeric or character

From what I guess, this might be what you are looking for:

``````data want;
format dsname \$41.;
set
table1
table2
table3
table4
table5
indsname=inname
;
where momr in (1,10,99);
dsname = inname;
run;``````

Since the variable named as indsname can't be included in the output dataset, we have to create a suitable variable of length 41 (8 bytes max for library name, dot, 32 bytes max for dataset name) for that. Because the format statement comes before the set statement, dsname will be the first (leftmost) variable/column of the new dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Discussion stats
• 7 replies
• 155 views
• 0 likes
• 2 in conversation