I am trying to merge two dataset of unequal rows but after merging i got completely empty data. The first dataset has 50 columns and 6320 rows while the second dataset has 5 columns and 220 rows. was trying to merge by a common variable but I got empty data after my merge. This is my code, what am i missing?
data BTS201505WTHR (drop=div:);
merge BTS201505 WTHRDATA(keep= FlightDate PRCP SNWD SNOW TMAX TMIN);
by FlightDate ;
if Origin='ORD';
run ;
Looks as if the subsetting-if does not what you expect it to do. Right now you drop any observation not having "ORD" as value of Origin, so checking the values of the variable is the first thing i would do.
@Tbell1 wrote:
I removed the if subset but there was no difference, i still got empty columns for the merged dataset
Have read the log? Are there any unexpected notes? Can you post the log as text, not as screenshot, not as attachment?
In case the columns in your keep list for the 2nd data set are empty then they will overwrite same named columns from your first data set.
WTHRDATA(keep= FlightDate PRCP SNWD SNOW TMAX TMIN);
For cases where there is no match between the DS over FlightDate all columns from the DS not contributing to the obs will be missing.
Are there any other case where you've got missings in a column that isn't already missing in the source table?
The merge statement is already so long around that it's certainly not a SAS bug so it must be either merge logic or source data.
Check whether or not you are actually getting any matches. Are you expecting a one to one match? A one to many match? Or a many to many match?
You can use the IN= datastep option to create a variable with indicator of whether that dataset contributes to the merge.
Assign the values to a new variable to keep them in the results.
data BTS201505WTHR (drop=div:);
merge BTS201505(in=in1)
WTHRDATA(in=in2 keep= FlightDate PRCP SNWD SNOW TMAX TMIN)
;
by FlightDate ;
length source $32 ;
if in1 and in2 then source='BOTH';
else if in1 then source='BTS201505';
else source='WTHRDATA';
run ;
proc freq ;
tables source;
run;
Do the variables from the second dataset (PRCP SNWD SNOW TMAX TMIN) already exist in the first dataset?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.