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

This works :

data xy;
input a  b ;
z=a/b;
datalines ;
123 123
123 456
123 234
;
run;

but this does not :

data xy;
input a  b ;
datalines ;
123 123
123 456
123 234
;
z=a/b;
run;

Can someone tell me why ? What's going on in the back-end ?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
The last semicolon after a datalines/cards statement indicates the end of the data step (you don't need the RUN) and since the data step is terminated, the calculation doesn't make sense because you're now in 'open code' with no data reference. This behaviour is noted in the documentation.

View solution in original post

3 REPLIES 3
Reeza
Super User
The last semicolon after a datalines/cards statement indicates the end of the data step (you don't need the RUN) and since the data step is terminated, the calculation doesn't make sense because you're now in 'open code' with no data reference. This behaviour is noted in the documentation.
Tom
Super User Tom
Super User

You cannot calculate a new variable after the data step has already been compiled and run.

What is confusing you is the spurious RUN: statement in your first example.  That is NOT part of the data step.

 

Another reason to not add that spurious RUN; statement after the end of a data step that is reading in-line data when posting example code. Besides wasting a line in your program file It will confuse novice programmers.

Kurt_Bremser
Super User

From the documentation of the DATALINES Statement:

 

Using the DATALINES Statement

The DATALINES statement is the last statement in the DATA step and immediately precedes the first data line. Use a null statement (a single semicolon) to indicate the end of the input data.
 
(emphasis by me)
 
That's why Maxim 1 is Maxim ONE.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 930 views
  • 6 likes
  • 4 in conversation