BookmarkSubscribeRSS Feed
sourav22
Calcite | Level 5

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! 

3 REPLIES 3
sourav22
Calcite | Level 5

Every table has the same set of weeks. And every table has only one row per week.

Table A Table B Table C 
WeekVariable_1WeekVariable_2WeekVariable_3
6-Nov-1616-Nov-16a6-Nov-16g
13-Nov-16213-Nov-16b13-Nov-16h
20-Nov-16320-Nov-16c20-Nov-16j
27-Nov-16427-Nov-16d27-Nov-16k
4-Dec-1654-Dec-16e4-Dec-16l

 

The above mentioned tables have to be consolidated as below:

 

Final Result Set in Teradata Table
WeekVariable_1Variable_2Variable_3
6-Nov-161ag
13-Nov-162bh
20-Nov-163cj
27-Nov-164dk
4-Dec-165el

 

 

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.

 

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 771 views
  • 1 like
  • 2 in conversation