DATA Step, Macro, Functions and more

Quick Answer Hopefully: Where is the syntax error?

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Quick Answer Hopefully: Where is the syntax error?

Hello, it would be much appreciated, if somone could point out the syntax error.

 

The contents of the raw data file CALENDAR are listed below:
--------10-------20-------30
01012000
The following SAS program is submitted:
data test;
infile 'calendar';
input @1 date mmddyy10.;
if date = '01012000'd then event = 'January 1st';
run;
Which one of the following is the value of the EVENT variable?

A. The value can not be determined as the program fails to execute due to errors
B. . (missing numeric value)
C. January 1st
D. 01012000

Answer: A.


Accepted Solutions
Solution
‎01-05-2016 04:38 PM
Super User
Posts: 10,516

Re: Quick Answer Hopefully: Where is the syntax error?

Date literals are in the form of "10Jan2016"d. The case is optional and quotes may be single or double but the month must be the 3 letter abbreviation and either the last 2 digits of year or the 4 digit version.

View solution in original post


All Replies
Solution
‎01-05-2016 04:38 PM
Super User
Posts: 10,516

Re: Quick Answer Hopefully: Where is the syntax error?

Date literals are in the form of "10Jan2016"d. The case is optional and quotes may be single or double but the month must be the 3 letter abbreviation and either the last 2 digits of year or the 4 digit version.

Contributor
Posts: 24

Re: Quick Answer Hopefully: Where is the syntax error?

Hey ballardw, are you saying SAS can only read "JAN", "FEB", ... as the month from raw data files? I must have missed that during my studying, but that sounds a bit troublesome. So SAS would not be able to read a raw data file that contains 01012000 or 01/01/2000 or 31/12/200 or JAN122000? That would be interesting to note.

Contributor
Posts: 24

Re: Quick Answer Hopefully: Where is the syntax error?

Wait hold on. I think I see the error. By Date literal, you the "01012000"d part. Not the info in the raw data file. Thanks much. That helps!

Super User
Posts: 17,868

Re: Quick Answer Hopefully: Where is the syntax error?

Super User
Posts: 17,868

Re: Quick Answer Hopefully: Where is the syntax error?

Did you try running the code? The log should help you out here.

1152 data test;
1153 infile 'calendar';
1154 input @1 date mmddyy10.;
1155 if date = '01012000'd then event = 'January 1st';
-----------
77
ERROR: Invalid date/time/datetime constant '01012000'd.
ERROR 77-185: Invalid number conversion on '01012000'd.

1156 cards;

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

Re: Quick Answer Hopefully: Where is the syntax error?

Hey Reeza, I have limited access to the SAS program, so I usually can't run the codes. I do research questions on Google before posting them. However, this one had no explanations and posting it is my way of contributing a discussion on the question, so that future SAS users can find it.
Super User
Posts: 17,868

Re: Quick Answer Hopefully: Where is the syntax error?

You can use SAS University Edition for learning purposes, even if you're not a student. It's free, as well as the first SAS course. Run at home or via AWS.

And that's not what @ballardw is saying. He's specifying that in code to let SAS know you're referring to a date you specify if it in a specific format. This is a good idea since it means all date literals in code have the same format, consistency is good Smiley Happy SAS can read in many different date formats and compare them as long as they're in a SAS date format. It's worth reading some papers on how SAS stores dates. I recommend searching lexjansen.com for papers that people have written.

Contributor
Posts: 24

Re: Quick Answer Hopefully: Where is the syntax error?

Yeah, I have SAS Uni. But I can't access it at work... strict downloading restrictions. Anyways, thanks for the help!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 325 views
  • 1 like
  • 3 in conversation