Hi Everyone,
I have multiple SAS data sets generated from different tables in a single folder. All the SAS datasets have a common column which is the week and along with the week are the variables of those particular tables. Now, I would want to load all these SAS datasets in a single Teradata table with one week column and all the variables from all the other tables into it. A code for this would be really helpful.
Please suggest a way for this.
Thankyou in advance!
What is the relationship of these tables with regard to week? Does every table only have one row per week?
Every table has the same set of weeks. And every table has only one row per week.
Table A | Table B | Table C | |||
Week | Variable_1 | Week | Variable_2 | Week | Variable_3 |
6-Nov-16 | 1 | 6-Nov-16 | a | 6-Nov-16 | g |
13-Nov-16 | 2 | 13-Nov-16 | b | 13-Nov-16 | h |
20-Nov-16 | 3 | 20-Nov-16 | c | 20-Nov-16 | j |
27-Nov-16 | 4 | 27-Nov-16 | d | 27-Nov-16 | k |
4-Dec-16 | 5 | 4-Dec-16 | e | 4-Dec-16 | l |
The above mentioned tables have to be consolidated as below:
Final Result Set in Teradata Table | |||
Week | Variable_1 | Variable_2 | Variable_3 |
6-Nov-16 | 1 | a | g |
13-Nov-16 | 2 | b | h |
20-Nov-16 | 3 | c | j |
27-Nov-16 | 4 | d | k |
4-Dec-16 | 5 | e | l |
All these SAS Datasets(Variable_1,Variable_2 and so on) are available in a folder. There are around 500 datasets. How to select them all and consolidate and load to a Teradata table as mentioned above.
The basic step would look like:
data teradata.target;:
merge
ds1
ds2
....
dsN
;
by week;
run;
which will put all variables side-by-side (week will appear only once, of course).
Depending on the name structure of your existing datasets, you will either have the option of using dataset lists (Mergin with Dataset Lists), or you might have to use a macro to insert the list of dataset names in the merge statement.
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.