Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proc Append....I think

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hello

I'm very new to SAS (using 9.0) so please don't laugh too hard if this is an easy question!

I have a very large text file that I am importing. The first data set is for specific institutions and the second dataset is for specific residence codes minus the institution codes from the first data set.

I can do that no problem but my issue is with trying to append the second dataset to the first at runtime. I have been able to do it by first creating the second set and then appending the files but I want to append while running the second so I don't have such huge files on my computer.

OR if there is a way to create one file from both data programs that would be good too.

Below is my code:

1.
data mylib.NACRS2005Hosp;
infile 'd:\Data Files\Data Release\NACRS.FY200405.txt' LRECL = 3000;
input @1 Inst $5.;
if Inst not in ('53987','54108','54197','54241','54249','54258','54320','54413') then delete;
input @6 Fyear $4.
@10 Period 2.
@35 IssProv $2.
@59 Enc $3.
@62 Postal $6.
@68 Rescode $7.
@75 Sex $1.
@85 FP $1.;

run;

2.
data mylib.NACRS2005Res;
infile 'd:\Data Files\Data Release\NACRS.FY200405.txt' LRECL = 3000;
input @1 Inst $5.;
if Inst in ('53987','54108','54197','54241','54249','54258','54320','54413') then delete;
input @6 Fyear $4.
@10 Period 2.
@35 IssProv $2.
@59 Enc $3.
@62 Postal $6.
@68 Rescode $7.;
If Rescode not in ('3301','3302','3305','3306','3307','3317','3329','3331','3334','3337','3338','3341','3344','3345','3346','3347','3348','2001','2002','2003','2004','2005','2006','2007','2008','0731','0739','0832','2721','3319') then
input @75 Sex $1.
@85 FP $1.;

run;

Any and all assistance greatly appreciated.

Shelby
 
Ah! This is a nice easy one actually, but not necessarily well known.
You can read multiple files in one datastep, the easiest way to do this is to define the filename statement with multiple files in it, like this
Code:
filename myfiles ("d:\Data Files\Data Release\NACRS.FY200405.txt"
                 ,"d:\Data Files\Data Release\NACRS.FY200405.txt");

data mylib.NACRS2005;
  infile myfiles LRECL = 3000;
  input @1        Inst            $5.;
  ...
  ...
run;
You can also use wildcards in the filenames so you could change the first one to d:\Data Files\Data Release\*.txt and exclude the second filename.
Note that you have to use " rather than ' when using this technique and you must use the brackets.

Enjoy.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Hi Chris

Sorry but I don't fully understand. What you're saying is that you indicate the input file twice and then include one set of parameters (for case 1 it is the institutions only) and for case 2 it is the residence codes minus the institutions? Do I still need to include all inputs?

Can you elaborate the code above with some sample inputs?

Thanks.

Shelby
 
Hi Shelby,
I'm sorry, I've just re-read your original post, and I don't understand. I thought you had 2 different datasets, I misread that. I don't understand why you're splitting one file apart then trying to append them back together again.
Do you mean append (adding the records from 1 file to the end of another file) or join (add fields/columns from 1 file to another file)?
If you are appending, then there's no point in creating 2 separate datasets in the first place as it all starts in one file. You should be able to easily combine the 2 input data steps into 1 step to just create 1 dataset.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top