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 

processing external files- SAS

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


Joined: 23 Aug 2005
Posts: 12
Topics: 10

PostPosted: Wed Oct 19, 2005 1:42 pm    Post subject: processing external files- SAS Reply with quote

hi,
i want to write the common records which are present in both files to a third file. my files and the code i'm trying is
Code:

file 1-
one
two
three
four
five

file 2-
september
october
one
december
january
monday
two
february
march
may
july
four


and output file should contain
one
two
four

now my code is-
Code:

data one;
infile file1;
input @001 recf1 $char3;
do;
  infile file2;
  input @001 recf2 $char3;
  if(recf2=recf1) then
  do;
      file file3;
      put @001 recf1 $char3.;
  end;
end;
return;
run;


but with this code i'm getting empty output file. i think there is something wrong with do loop. how to write nested do loops , if i want to read one external file completely for each record in the other file ?
_________________
Thanks,
Gayatri.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Oct 19, 2005 2:20 pm    Post subject: Reply with quote

yathri,

check this link which explains in detail about matching in sas

http://www.ats.ucla.edu/stat/sas/modules/merge.htm

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
yatri
Beginner


Joined: 23 Aug 2005
Posts: 12
Topics: 10

PostPosted: Thu Oct 20, 2005 12:00 am    Post subject: Reply with quote

Thanks Kolusu.
but then the approach which i'm trying , i believe it should also work. can anybody please help me finding out what is wrong with my code?
_________________
Thanks,
Gayatri.
Back to top
View user's profile Send private message
pzmohanty
Beginner


Joined: 20 May 2004
Posts: 97
Topics: 43
Location: hyderabad, India

PostPosted: Tue Feb 07, 2006 4:54 pm    Post subject: Reply with quote

Hi Yatri,

Another crude way to acieve what you are looking for :-

1) convert the flat files into corresponding SAS files in SAS code

2) use following SQL to extract common record.
PROC SQL;
Create view V1 as select a.field from F1 a, F2 b where a.field = b.field ;

3) write the records of view V1 to output file.
_________________
Priya Ranjan Mohanty
Consultant
Kanbay Software (I) pvt. Ltd.
Hyderabad
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
advoss
Beginner


Joined: 23 Aug 2005
Posts: 26
Topics: 0

PostPosted: Mon Feb 13, 2006 5:20 pm    Post subject: Reply with quote

Code:

/* here is one variation of the solution as suggested by Priya */
/* It would be possible to do it in a single data step, but that */
/* data step would become significantly complicated and, to ensure */
/* that all matches were found, the data would either have to be */
/* presorted (if that is the case, my following example would be */
/* simpler) or multiple passes would have to be made through */
/* one of the input files. */
data vfile1/view=vfile1;
  length recf1 $10;
  infile file1;
  input @001 recf1 $cha10.;
run;
data vfile2/view=vfile2;
  length recf2 $10;
  infile file2;
  input @001 recf2 $char10.;
run;
proc sql noprint;
  create table matches as
    select t1.recf1
       from vfile1 t1 inner join vfile2 t2
       on t1.recf1 = t2.recf2
       ;
  quit;
data _null_;
  set matches;
  file file3;
  put @1 recf1 $char10.;
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 -> Utilities 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