/*Example 7: Merging datasets*/
Data EmpA;
Input First $ Gender $ EmpID;
datalines;
Togar M 121150
Kylie F 121151
Birin M 121152
;
Run;
Data EmpB;
Input EmpID Phone $16.;
datalines;
121150 +61(2)5555-1793
121151 +61(2)5555-1849
121152 +61(2)5555-1665
;
run;
proc print data=EmpB;
run;
data EmpAB;
Merge EmpA EmpB; /*Merge replaces the set for side-by-side combining*/
by EmpID; /*By statement variable must be within each data set*/
/*Usually need to sort by the
same variable in each data set*/
Run;
proc print data=EmpAB;
run;
This is my output data and I know it is incorrect. What should I change in my code ?
Specify the delimiter appropriately, in this case a Tab as mentioned by @Astounding
/*Example 7: Merging datasets*/ Data EmpA; infile cards dlm='09'x; Input First $ Gender $ EmpID; datalines; Togar M 121150 Kylie F 121151 Birin M 121152 ; Run; Data EmpB; infile cards dlm='09'x; Input EmpID Phone $16.; datalines; 121150 +61(2)5555-1793 121151 +61(2)5555-1849 121152 +61(2)5555-1665 ; run;
@Godzilla_Hat wrote:
/*Example 7: Merging datasets*/ Data EmpA; Input First $ Gender $ EmpID; datalines; Togar M 121150 Kylie F 121151 Birin M 121152 ; Run; Data EmpB; Input EmpID Phone $16.; datalines; 121150 +61(2)5555-1793 121151 +61(2)5555-1849 121152 +61(2)5555-1665 ; run; proc print data=EmpB; run; data EmpAB; Merge EmpA EmpB; /*Merge replaces the set for side-by-side combining*/ by EmpID; /*By statement variable must be within each data set*/ /*Usually need to sort by the same variable in each data set*/ Run; proc print data=EmpAB; run;
This is my output data and I know it is incorrect. What should I change in my code ?
@Godzilla_Hat wrote:
/*Example 7: Merging datasets*/ Data EmpA; Input First $ Gender $ EmpID; datalines; Togar M 121150 Kylie F 121151 Birin M 121152 ; Run; Data EmpB; Input EmpID Phone $16.; datalines; 121150 +61(2)5555-1793 121151 +61(2)5555-1849 121152 +61(2)5555-1665 ; run; proc print data=EmpB; run; data EmpAB; Merge EmpA EmpB; /*Merge replaces the set for side-by-side combining*/ by EmpID; /*By statement variable must be within each data set*/ /*Usually need to sort by the same variable in each data set*/ Run; proc print data=EmpAB; run;
This is my output data and I know it is incorrect. What should I change in my code ?
The code and generated data does not generate the result shown. The result you show means that you forced reading the Empid into the Gender, which typically means the data was read incorrectly, possibly incorrect use of column input instead of list.
SAS expects to find blanks between the variables in the DATALINES section.
You used tabs, not blanks.
You can use tabs, but then you would need to add an INFILE statement and an option to tell SAS you are using tabs instead of blanks to delimit your variables. It might be easiest to re-type the data, using spaces in between your variables.
Specify the delimiter appropriately, in this case a Tab as mentioned by @Astounding
/*Example 7: Merging datasets*/ Data EmpA; infile cards dlm='09'x; Input First $ Gender $ EmpID; datalines; Togar M 121150 Kylie F 121151 Birin M 121152 ; Run; Data EmpB; infile cards dlm='09'x; Input EmpID Phone $16.; datalines; 121150 +61(2)5555-1793 121151 +61(2)5555-1849 121152 +61(2)5555-1665 ; run;
@Godzilla_Hat wrote:
/*Example 7: Merging datasets*/ Data EmpA; Input First $ Gender $ EmpID; datalines; Togar M 121150 Kylie F 121151 Birin M 121152 ; Run; Data EmpB; Input EmpID Phone $16.; datalines; 121150 +61(2)5555-1793 121151 +61(2)5555-1849 121152 +61(2)5555-1665 ; run; proc print data=EmpB; run; data EmpAB; Merge EmpA EmpB; /*Merge replaces the set for side-by-side combining*/ by EmpID; /*By statement variable must be within each data set*/ /*Usually need to sort by the same variable in each data set*/ Run; proc print data=EmpAB; run;
This is my output data and I know it is incorrect. What should I change in my code ?
I seem to recall you had exactly the same problem in another of your posts - tabs between DATALINE fields.
Since you are new to SAS I suggest you avoid using tabs in DATALINEs as they appear to be causing you confusion. The very fact that they are not visible in the SAS editor is the likely cause.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.