Hello,all:
I have some questions:
1, I would like to compare two data sets, some variables has the same name but different positions, how to set a flag to find them, and how to ignore. For example, the variable “ID” has the name of “John” but one is at the left of the column and the other is at the center of the column.
With all above, which statement I should be use? Please advice, thanks.
@ybz12003 wrote:
Hello,all:
I have some questions:
1, I would like to compare two data sets, some variables has the same name but different positions, how to set a flag to find them, and how to ignore. For example, the variable “ID” has the name of “John” but one is at the left of the column and the other is at the center of the column.
- If sometimes “John” is all in capital “JOHN”, and the other case is in “john”. How to let the system know they refer the same person, and it could be ignore.
With all above, which statement I should be use? Please advice, thanks.
First, you have to merge the two datasets, using the MERGE statement of a data step, or using PROC SQL.
Capitalization is easy to deal with, just compare the all caps (or all lower case) version of the text, in other words, you can compare UPPER(variable1) to UPPER(variable2). If the text isn't always at the left hand side, you can use the LEFT function to force the text to be at the left hand side. You also want to use the TRIM function to get rid of trailing blanks which could cause the comparison to fail.
so, a data step comparison would look something like
if trim(left(upper(variable1))) = trim(left(upper(variable2))) then ...
@ybz12003 wrote:
Hello,all:
I have some questions:
1, I would like to compare two data sets, some variables has the same name but different positions, how to set a flag to find them, and how to ignore. For example, the variable “ID” has the name of “John” but one is at the left of the column and the other is at the center of the column.
- If sometimes “John” is all in capital “JOHN”, and the other case is in “john”. How to let the system know they refer the same person, and it could be ignore.
With all above, which statement I should be use? Please advice, thanks.
First, you have to merge the two datasets, using the MERGE statement of a data step, or using PROC SQL.
Capitalization is easy to deal with, just compare the all caps (or all lower case) version of the text, in other words, you can compare UPPER(variable1) to UPPER(variable2). If the text isn't always at the left hand side, you can use the LEFT function to force the text to be at the left hand side. You also want to use the TRIM function to get rid of trailing blanks which could cause the comparison to fail.
so, a data step comparison would look something like
if trim(left(upper(variable1))) = trim(left(upper(variable2))) then ...
or this suggestion here? Proc compare ignore case specificity
How to write the command?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.