DATA Step, Macro, Functions and more

Table Combination

Reply
Contributor
Posts: 40

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
1param1.090.210.15
1T(6.22)(3.26)(3.08)
2param1.090.210.15
2T(6.20)(3.46)(3.42)
3param1.000.130.07
3T(5.83)(2.28)(1.71)
4param1.040.170.10
4T(6.01)(2.79)(2.34)
5param0.970.07-0.01
5T(5.33)(1.05)(-0.32)
6param0.980.06-0.03
6T(5.05)(0.77)(-0.68)
7param0.90-0.05-0.16
7T(4.30)(-0.58)(-2.98)
8param0.78-0.21-0.32
8T(3.46)(-2.00)(-5.47)
9param0.67-0.34-0.48
9T(2.77)(-2.78)(-6.66)
10param0.27-0.77-0.95
10T(1.01)(-5.10)(-10.01)
99param-0.83***-0.98***-1.10***
99T(-6.04)(-7.75)(-11.34)

 

I really appreciate if someone can help me with it. 

Super User
Posts: 7,857

Re: Table Combination

Posted in reply to yotsuba88

What name should be contained in your new variable?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 40

Re: Table Combination

Posted in reply to KurtBremser
I mean it just like Jump for 1st table, IV for 2nd table

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 7,857

Re: Table Combination

Posted in reply to yotsuba88

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 40

Re: Table Combination

Posted in reply to KurtBremser
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.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 7,857

Re: Table Combination

Posted in reply to yotsuba88

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
Contributor
Posts: 40

Re: Table Combination

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


##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 7,857

Re: Table Combination

Posted in reply to yotsuba88

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

Try to follow this guideline in your posts to avoid confusion.

 

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
Ask a Question
Discussion stats
  • 7 replies
  • 131 views
  • 0 likes
  • 2 in conversation