Help using Base SAS procedures

PROC IMPORT vs. infile?

Reply
Occasional Contributor
Posts: 7

PROC IMPORT vs. infile?

I am a SAS novice. I wrote up code using a "fake" data set so that I could be sure the code worked when I had data. However, I used an infile line to read in the fake data, and PROC IMPORT to read in the real data. Almost everything works the same, except 2 variables I create in the data step (marked in bold)

Here is the original code, where i read in the data from a .txt file, and the 2 variables are created and work fine.

data PatientEval;
filename data 'U:\Patient Eval Study\Fake Patient Eval Data Errors.txt';
infile data DLM = '09'X DSD;


input ID Resident_ID Program Year
Question_1 Question_2 Question_3 Question_4 Question_5 Question_6
Question_7 Question_8 Question_9 Question_10 Question_11 AIDET_1
AIDET_2 AIDET_3 AIDET_4 AIDET_5
;

pYear = Program*10 + Year; /*Creates a variable that reads both Program and Year*/

noCount = 0; /* Counts how many "no" answers for AIDET Questions are given*/
if AIDET_1 = 0 then noCount = noCount+1;
if AIDET_2 = 0 then noCount = noCount+1;
if AIDET_3 = 0 then noCount = noCount+1;
if AIDET_4 = 0 then noCount = noCount+1;
if AIDET_5 = 0 then noCount = noCount+1;


label Resident_ID = 'Resident ID'
Program = 'Program'
Year = 'Year'
Question_1 = 'Greeting'
Question_2 = 'Listens'
Question_3 = 'Interested'
Question_4 = 'Respectful'
Question_5 = 'Explicit'
Question_6 = 'Educate'
Question_7 = 'Comprehensible'
Question_8 = 'Collaborative'
Question_9 = 'Engaged'
Question_10 = 'Straightforward'
Question_11 = 'Diplomatic'
pYear = 'Program and Year'
AIDET_1 = 'Acknowledge'
AIDET_2 = 'Introduce'
AIDET_3 = 'Duration'
AIDET_4 = 'Explain'
AIDET_5 = 'Thank'
noCount = 'Number of Failed AIDET Questions';
;

Here is the new code, with the IMPORT procedure. The 2 variables aren't created here.

PROC IMPORT OUT= WORK.PatientEval
DATATABLE= "Data Code"
DBMS=ACCESS REPLACE;
DATABASE="N:\ACGME Competencies\360\Fall 2008 Patient Evaluation\Fall 2008 Patient Evaluation Database.mdb";
SCANMEMO=YES;
USEDATE=NO;
SCANTIME=YES;
RUN;

data PatientEval

input ID Resident_ID Program Year
Question_1 Question_2 Question_3 Question_4 Question_5 Question_6
Question_7 Question_8 Question_9 Question_10 Question_11 AIDET_1
AIDET_2 AIDET_3 AIDET_4 AIDET_5
;

pYear = Program*10 + Year; /*Creates a variable that reads both Program and Year*/

noCount = 0; /* Counts how many "no" answers for AIDET Questions are given*/
if AIDET_1 = 0 then noCount = noCount+1;
if AIDET_2 = 0 then noCount = noCount+1;
if AIDET_3 = 0 then noCount = noCount+1;
if AIDET_4 = 0 then noCount = noCount+1;
if AIDET_5 = 0 then noCount = noCount+1;


label Resident_ID = 'Resident ID'
Program = 'Program'
Year = 'Year'
Question_1 = 'Greeting'
Question_2 = 'Listens'
Question_3 = 'Interested'
Question_4 = 'Respectful'
Question_5 = 'Explicit'
Question_6 = 'Educate'
Question_7 = 'Comprehensible'
Question_8 = 'Collaborative'
Question_9 = 'Engaged'
Question_10 = 'Straightforward'
Question_11 = 'Diplomatic'
pYear = 'Program and Year'
AIDET_1 = 'Acknowledge'
AIDET_2 = 'Introduce'
AIDET_3 = 'Duration'
AIDET_4 = 'Explain'
AIDET_5 = 'Thank'
noCount = 'Number of Failed AIDET Questions';
;


The log error is:

ERROR: NO DATALINES OR INFILE STATEMENT.

How do I get the variables to work in the 2nd instance?

Thanks,
Ashley Adams
SEAHEC
SAS Super FREQ
Posts: 8,743

Re: PROC IMPORT vs. infile?

Hi:
Once you have already created a SAS data set with PROC IMPORT, you would then only need a SET statement to reference that dataset:
[pre]
PROC IMPORT OUT= WORK.PatientEval
DATATABLE= "Data Code"
DBMS=ACCESS REPLACE;
DATABASE="N:\ACGME Competencies\360\Fall 2008 Patient Evaluation\Fall 2008 Patient Evaluation Database.mdb";
SCANMEMO=YES;
USEDATE=NO;
SCANTIME=YES;
RUN;

data NewPatientEval;
set work.patienteval;

pYear = Program*10 + Year;

noCount = 0; /* Counts how many "no" answers for AIDET Questions are given*/
if AIDET_1 = 0 then noCount = noCount+1;
if AIDET_2 = 0 then noCount = noCount+1;
if AIDET_3 = 0 then noCount = noCount+1;
if AIDET_4 = 0 then noCount = noCount+1;
if AIDET_5 = 0 then noCount = noCount+1;
... more code ...
run;

proc print data=NewPatientEval;
run;
[/pre]

In other words, WORK.PATIENTEVAL is the output from what you read with PROC IMPORT and WORK.NEWPATIENTEVAL is the output from the step or program where you create your new variables.

Although you could do this:
[pre]
data patienteval;
set patienteval;
...more code...
run;
[/pre]

I am not a fan of coding this type of DATA step program, where you have the same dataset name for input (SET statement) and output (DATA statement). So, I would recommend, instead that you use this convention:

[pre]
data newpatienteval;
set patienteval;
...more code...
run;
[/pre]

The PROC IMPORT step is taking the place of the INPUT in the first program. If you want your final dataset to have the name work.patienteval, then simply change the Proc Import step to create WORK.IMP_PT or something. If you did this, then your final code could be:
[pre]
data work.patienteval;
set work.imp_pt;
...more code...
run;
[/pre]

The advantage of the approach in the 1st program is that you are reading the data into SAS data set form AND creating your new variables in one pass through the data.

cynthia
Occasional Contributor
Posts: 7

Re: PROC IMPORT vs. infile?

Thank you!

That's all I needed. I appreciate the help!
Ask a Question
Discussion stats
  • 2 replies
  • 1480 views
  • 0 likes
  • 2 in conversation