BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Godzilla_Hat
Obsidian | Level 7
/*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;

Godzilla_Hat_0-1634158794763.png

This is my output data and I know it is incorrect. What should I change in my code ?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

Godzilla_Hat_0-1634158794763.png

This is my output data and I know it is incorrect. What should I change in my code ?


 

View solution in original post

4 REPLIES 4
ballardw
Super User

@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;

Godzilla_Hat_0-1634158794763.png

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.

Astounding
PROC Star

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.

Reeza
Super User

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;

Godzilla_Hat_0-1634158794763.png

This is my output data and I know it is incorrect. What should I change in my code ?


 

SASKiwi
PROC Star

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: Register Now

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!

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
  • 4 replies
  • 787 views
  • 4 likes
  • 5 in conversation