DATA Step, Macro, Functions and more

Merging Dataset Dynamically with New Column Name added to specify file name

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Merging Dataset Dynamically with New Column Name added to specify file name

I would like to append 16 datasets having same column and variables name. I would like to do that using macro to stack each table

and create one with new variable having dataset name to distinguish the data in merged table.

 

Please suggest.

 

Example : I have Table Customer and Client having variable as  A ,B,C, D..and soon on.

 

Would like to create one table MERGED

AS data from both table and new variable

A   B      NEW_VARIABLE

1    0      Customer_file

1    0       Client_file

 

So that data can be differentiated based on New_variable.?

 

 

 


Accepted Solutions
Solution
‎06-27-2016 09:46 AM
Contributor
Posts: 26

Re: Merging Dataset Dynamically with New Column Name added to specify file name

I have created this through SQL while calculating percentage difference between two values and displayed in a table.

 

 

View solution in original post


All Replies
Respected Advisor
Posts: 4,644

Re: Merging Dataset Dynamically with New Column Name added to specify file name

Use set statement option indsname= 

 

data all;

set A B C D E F G indsname=dsn;

NEW_VARIABLE = dsn;

run;

PG
Contributor
Posts: 26

Re: Merging Dataset Dynamically with New Column Name added to specify file name

Yes, The value of the new variable is same as the dataset name. That's why I need to write it in a macro. Please suggest
Respected Advisor
Posts: 4,644

Re: Merging Dataset Dynamically with New Column Name added to specify file name

Sorry, I don't understand the question. The simple code provided concatenates datasets A, B, C etc. and adds NEW_VARIABLE to the resulting dataset with the name of the dataset of origin. Do you mean some other sort of merging operation? Are you asking for a macro variable or macro program?

PG
Solution
‎06-27-2016 09:46 AM
Contributor
Posts: 26

Re: Merging Dataset Dynamically with New Column Name added to specify file name

I have created this through SQL while calculating percentage difference between two values and displayed in a table.

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 234 views
  • 0 likes
  • 2 in conversation