Here is my code:
data school;
input age quiz : $1. midterm final;
datalines;
12 A 92 95
12 B 88 88
13 C 78 75
13 A 92 93
12 F 55 62
12 B 88 82
;
RUN;
data newschool;
infile school;
input age quiz : $1 midterm final;
if age = 12 then grade = 6;
else if age =13 then grade = 8;
run;
The error I get is:
ERROR: No logical assign for filename SCHOOL.
I don't really understand the difference between 'set' and 'infile'. It seems I have a fundamental misunderstanding of what is going on, so I'd like to clear it up.
Once you have created the data set named SCHOOL, to use it in another data step, you use SET.
If you want to read data from a text (or csv or similar) file, then you use INFILE.
So, I changed 'infile' to 'set' and got this error:
No DATALINES or INFILE statement
data school;
input age quiz : $1. midterm final;
if age = 12 then grade = 6;
else if age =13 then grade = 8;
datalines;
12 A 92 95
12 B 88 88
13 C 78 75
13 A 92 93
12 F 55 62
12 B 88 82
;
RUN;
data newschool;
set school;
input age quiz : $1 midterm final;
if age = 12 then grade = 6;
else if age =13 then grade = 8;
run;
When you use SET, you usually won't also do an INPUT. You already did the INPUT for data set SCHOOL when it was created, so you don't need another INPUT to use data set SCHOOL.
@Astounding wrote:
This isn't what you asked, but it's something you need to know. You don't need two DATA steps. You can move the IF THEN logic to just before the DATALINES statement in your first DATA step.
Having seen code where people created a dozen or so data sets each adding a single variable (and then getting lost later as to which set to use) I heartily agree with this.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.