View previous topic :: View next topic |
Author |
Message |
yatri Beginner
Joined: 23 Aug 2005 Posts: 12 Topics: 10
|
Posted: Wed Oct 19, 2005 1:42 pm Post subject: processing external files- SAS |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
yatri Beginner
Joined: 23 Aug 2005 Posts: 12 Topics: 10
|
Posted: Thu Oct 20, 2005 12:00 am Post subject: |
|
|
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 |
|
 |
pzmohanty Beginner

Joined: 20 May 2004 Posts: 97 Topics: 43 Location: hyderabad, India
|
Posted: Tue Feb 07, 2006 4:54 pm Post subject: |
|
|
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 |
|
 |
advoss Beginner
Joined: 23 Aug 2005 Posts: 26 Topics: 0
|
Posted: Mon Feb 13, 2006 5:20 pm Post subject: |
|
|
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 |
|
 |
|
|