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.
What name should be contained in your new variable?
If you want those values automatically assigned in the data step, from where do you get them?
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?
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.