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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

8 REPLIES 8
ballardw
Super User

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.

Durlov
Obsidian | Level 7

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.

Durlov
Obsidian | Level 7

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!

Reeza
Super User
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
Durlov
Obsidian | Level 7
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.
Reeza
Super User
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 🙂 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.

Durlov
Obsidian | Level 7

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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