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.

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

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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