BookmarkSubscribeRSS Feed
Sandeep77
Lapis Lazuli | Level 10

Hi, I have merged two files and send for processing. I have the files back after additional information but need to unmerge the file now. I used below code to merge the file:

data abc;
set
work.abc_external_13jan2022
work.abc_internal_13jan2022;
run;

 

%let pname = Full_13012022;

 

proc export data=work.abc
outfile= "\\llocal\shares\Public\\Send files\abc_&pname..csv" dbms=csv replace;
run;

 

Thanks

2 REPLIES 2
Kurt_Bremser
Super User

This is not a merge, but a so-called "stack". For a merge you woukd use the MERGE statement.

To correctly "unstack" the data you need a variable that has a limited list of values (or just a single value) in one dataset and none of these in the other. A simple example using SASHELP.CLASS:

data
  female
  male
;
set sashelp.class;
if sex = "F"
then output female;
else output male;
run;
ballardw
Super User

An easy way to get a variable to identify the source of data is the INDSNAME data set option.

Run this code on your data:

data abc;
   set
      work.abc_external_13jan2022
      work.abc_internal_13jan2022
      indsname=dsn
   ;
   source=dsn;
run;

You will find a variable named Source that has the name of the data set each record comes from.

The option Indsname creates a temporary variable with the name of the data set. To have it in the output you need to assign it to another variable.

 

Then it is easy to select the records for other processes.

 

Do note that because of the way SAS stores metadata about libraries and library members such as data sets that the name is in all uppercase text.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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