MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File Match/Merge in SAS

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
vijay
Beginner


Joined: 09 May 2003
Posts: 131
Topics: 64

PostPosted: Mon Jul 17, 2006 10:09 am    Post subject: File Match/Merge in SAS Reply with quote

Hi,
When I try to run this sample code I get an error.ID1 has been defined as char and numeric and same error with id2.I'm new to SAS.Help me in figuring out this error

Vijay
Code:

  DATA FILEIN1;                                           
     INFILE CARDS;                                         
     INPUT  @01  ID1   $CHAR2.;                           
                                                           
  CARDS;                                                   
 12                                                       
 11                                                       
 ;                                                         
  DATA FILEIN2;                                           
     INFILE CARDS;                                         
     INPUT  @01  ID2   $CHAR2.                             
            @04  NAME  $CHAR10.;                           
                                                           
  CARDS;                                                   
 12 NAME10                                                 
 11 NAME11                                                 
 ;                                                         
  PROC SORT DATA=FILEIN1;                                 
     BY ID1;                                               
  PROC SORT DATA=FILEIN2;                                 
     BY ID2;                                               
  DATA COMBINE;                                           
     LINK GETFILEIN1;                                     
     LINK GETFILEIN2;                                     
     DO WHILE (1=1);                                       
      IF (ID1=ID2) THEN                                   
       DO;                                                 
        OUTPUT;                                           
       END;                                               
      IF FILE1EOF AND FILE2EOF THEN STOP;                 
     END;                                                 
                                                           
 GETFILEIN1:                             
 IF EOF1 THEN                           
   DO;                                   
     FILE1EOF=1;                         
     RETURN;                             
   END;                                 
 SET FILEIN1  END=EOF1;                 
   RETURN;                               
                                         
 GETFILEIN2:                             
 IF EOF2 THEN                           
   DO;                                   
     FILE2EOF=1;                         
     RETURN;                             
   END;                                 
 SET FILEIN2 END=EOF2;                   
   RETURN;                               
                                         
 PROC PRINT DATA=FILEIN1;               
    TITLE 'PRINT FILEIN1 RECORDS ';     
 PROC PRINT DATA=FILEIN2;               
    TITLE 'PRINT FILEIN2 RECORDS ';     
 PROC PRINT DATA=COMBINE;               
    TITLE 'PRINT COMBINE RECORDS ';     
    VAR ID3 NAME3;                       
/*                                       
Back to top
View user's profile Send private message
jetson
Beginner


Joined: 07 Oct 2005
Posts: 30
Topics: 2
Location: Texas

PostPosted: Mon Jul 17, 2006 11:35 am    Post subject: Reply with quote

It's not clear what you are trying to accomplish. Joining the tables is much simpler than what you are doing...perhaps you want more than to just join the two tables by ID? Pleas explain.
Back to top
View user's profile Send private message
vijay
Beginner


Joined: 09 May 2003
Posts: 131
Topics: 64

PostPosted: Mon Jul 17, 2006 11:50 am    Post subject: Reply with quote

I'm just trying to compare files without merge jetson
Vijay
Back to top
View user's profile Send private message
jetson
Beginner


Joined: 07 Oct 2005
Posts: 30
Topics: 2
Location: Texas

PostPosted: Mon Jul 17, 2006 1:03 pm    Post subject: Reply with quote

PROC SQL should be much easier than data step (unless data step is required.) It looks like you're trying to process each record from the first table against each record from the second table...definitely a painful process if you have a lot of data.

PROC SQL can do the cartesian join and filtering...
Back to top
View user's profile Send private message
advoss
Beginner


Joined: 23 Aug 2005
Posts: 26
Topics: 0

PostPosted: Wed Jul 19, 2006 11:27 am    Post subject: Reply with quote

Why not use a merge? What are you looking for that it will not provide?
Code:

DATA COMBINE;
  merge filein1(rename=(ID1=ID) in=in1)
            filein2(rename=(ID2=ID) in=in2);
  by ID;
  if in1 then ID1 = ID;
  if in2 then ID2 = ID;
  drop ID;
run;

_________________
Alan Voss
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group