BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nietzsche
Lapis Lazuli | Level 10

Hi I am reading an example in SAS Essentials by Elliot (pg. 137) screenshot as follow

Capture.PNG

When I run the code without the two semicolons I circled, the result is exact the same as with the two circle semicolons.

the only difference is the there are two syntax error in the log

they are

What is the point of the two semicolon in the INPUT statement if SAS can generate the result them? 

I thought the purpose of the semicolon is to close a statement, when the first semicolon exist, should it immediately terminate the input statement?

 

ERROR 22-322: Syntax error, expecting one of the following: a name, arrayname, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. ERROR 76-322: Syntax error, statement will be ignored.

here is the code if anyone is interested

DATA DATES;
INPUT @1 BDATE MMDDYY8.;
TARGET=MDY(08,25,2009);
* Uses MDY() function;
AGE=INTCK('YEAR',BDATE,TARGET); * INTCK function;
DATALINES;
07101952
07041776
01011900
;
PROC PRINT DATA=DATES;
FORMAT BDATE WEEKDATE. TARGET MMDDYY8.;
RUN;
SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Patrick_0-1665629856071.png

That's exactly happens. The first semicolon terminates the input statement, the 2nd semicolon terminates code that assigns a value to a variable (this one has nothing to do with the input statement). 

 

Patrick_1-1665629997727.png

It can't. If you run your code in a fresh new SAS session without the semicolons then the target table won't get created. What you might see in your test is the "left over" from your first run with correct syntax.

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

Patrick_0-1665629856071.png

That's exactly happens. The first semicolon terminates the input statement, the 2nd semicolon terminates code that assigns a value to a variable (this one has nothing to do with the input statement). 

 

Patrick_1-1665629997727.png

It can't. If you run your code in a fresh new SAS session without the semicolons then the target table won't get created. What you might see in your test is the "left over" from your first run with correct syntax.

Nietzsche
Lapis Lazuli | Level 10

okay I think I fundamentally misunderstood the INPUT statement.

 

so if the variables data is not from DATALINES, then you don't need to use INPUT? You can simply define for example a constant variable without using INPUT before PROC MEANS/PRINT?

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
Patrick
Opal | Level 21

@Nietzsche 

From https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0oaql83drile0n141pdacojq97s.htm 

Patrick_0-1665641601892.png

 

Basically: The input statement is used to read EXTERNAL data into SAS VARIABLE.

Normally the INPUT statement is paired with the INFILE statement. The INFILE statement defines the external file (like where it's stored), and the input statement then reads the data.

DATALINES is for in-stream data (=data directly in the code) and though a bit of special case and normally only used to create some self-contained samples.

 

May-be reading below will create a bit more clarity for you.

Reading Raw Data

Reading External Files

 

And don't worry - just the normal confusion of a beginner. You'll get there. It's not that complicated.

 

Tom
Super User Tom
Super User

It definitely does NOT run the same if you convert three statements into one statement by removing the semicolons that end the first two statements.

686  DATA DATES;
687  INPUT @1 BDATE MMDDYY8.;
688  TARGET=MDY(08,25,2009);
689  * Uses MDY() function;
690  AGE=INTCK('YEAR',BDATE,TARGET); * INTCK function;
691  DATALINES;

NOTE: The data set WORK.DATES has 3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds


695  ;
696  DATA DATES;
697  INPUT @1 BDATE MMDDYY8.
698  TARGET=MDY(08,25,2009)
                --
                22
                76
ERROR 22-322: Syntax error, expecting one of the following: a name, arrayname, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 76-322: Syntax error, statement will be ignored.

699  * Uses MDY() function;
700  AGE=INTCK('YEAR',BDATE,TARGET); * INTCK function;
701  DATALINES;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATES may be incomplete.  When this step was stopped there were 0 observations and 4 variables.
WARNING: Data set WORK.DATES was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

705  ;

 

 

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
  • 4 replies
  • 720 views
  • 1 like
  • 3 in conversation