BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TimmySauce
Fluorite | Level 6

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. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
Hi, When you use a SET Statement, the INPUT statement is not required. All the variables you created in the first program are all available to you in the second program just based on the SET statement. This is one of the benefits of using a SET statement -- you do not have to "redefine" or "re-read" the variables.
Cynthia

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
TimmySauce
Fluorite | Level 6

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;

Cynthia_sas
SAS Super FREQ
Hi, When you use a SET Statement, the INPUT statement is not required. All the variables you created in the first program are all available to you in the second program just based on the SET statement. This is one of the benefits of using a SET statement -- you do not have to "redefine" or "re-read" the variables.
Cynthia
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Astounding
PROC Star
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.
ballardw
Super User

@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.

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 883 views
  • 6 likes
  • 5 in conversation