BookmarkSubscribeRSS Feed
datamgr85
Calcite | Level 5

I ran into a strange merge situation and am hoping someone can help me understand it. Here's a simplified version (the real one involved more datasets and more variables):

 

Dataset ONE, created by Proc Import from an Excel file, contained 2 variables: barcode and id

 

Dataset TWO, created from other SAS datasets, contained 3 variables: BARCODE, ID, and TRIAL

 

Dataset THREE, created by merging ONE and TWO by barcode (after sorting both datasets by barcode), had all 3 variables, as expected, but data for TRIAL and ID were missing.

 

After confirming type, length, label and format of all variables were identical, I changed the case of ONE variables to match TWO variables (i.e., all upper case, rather than all lowercase). I did not change any values, only variable names. When I did this, the merge worked and no values were missing.

 

If SAS variable names are case insensitive, how can this be explained?

3 REPLIES 3
Reeza
Super User

If SAS variable names are case insensitive, how can this be explained?

 

Variable names are case insensitive, but variable values are case sensitive. Also, if you're working with an RBDMS, ie connecting to a SQL server that may be case sensitive. 

datamgr85
Calcite | Level 5

Thanks, Reeza. I didn't change any values, only variable names. I will look into whether a SQL server could be the issue.

ballardw
Super User

There are a number of possible data combinations that would cause this.

One is if the ID in the first set has a barcode, is missing id and has not corresponding barcode in the other data.

Another is if the barcode matches but the second set the matching barcode has missing values for id and trial.

And also if the second set has barcode that doesn't have a match and is missing id and trial

Please see this example code:

data one;
   input barcode id;
datalines;
1234   567
3333   .
6666   123
;
run;

data two;
input barcode id trial;
datalines;
1234 567  8910
5555 888  9999
6666 .    .
7777 .    .
;
run;

data merged;
   merge
      one
      two
   ;
   by barcode ;
run;

 

 

I would suspect that your result is most likely something related to data such as these three cases.

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
  • 1104 views
  • 1 like
  • 3 in conversation