BookmarkSubscribeRSS Feed

Top 10 Syntax Errors and How to Fix Them. Q&A, Code, Slides, and On-Demand Recording

Started ‎03-25-2021 by
Modified ‎03-30-2021 by
Views 6,141

Top 10 Syntax Errors.jpg

 

Watch this Ask the Expert session to make sense of the sometimes-odd messages in your SAS log. Perfect for beginning and intermediate Base SAS programmers. 

 

Watch the webinar

 

Join Davetta Dunlap as she teaches you how to read your log to solve common syntax issues. During this webinar you will learn:

  • The most common syntax errors.
  • How to read your SAS log to fix those errors.
  • How to write better programs by eliminating these syntax errors.

The questions from the Q&A segment held at the end of the webinar are listed below. The slides and code examples from the webinar are attached.

 

Is there a difference between single and double quotations?

You can use single or double as long as they match. If you are using the Macro facility, you will need to use double quotes.

 

It is not an error, but if we want to have our own notes in a different color so it stands out - is that possible?  Currently I put them as Warnings, so they are in green color to stand out.

See demo at end of presentation in the Q&A session. This question is at minute 49 in the recording.

 

Why didn’t comma8 get a period?

We created a data set variable named comma8. Comma8 is not a reserved word in SAS, so you could have a variable/column with that name. SAS would know the difference between COMMA8 used as a variable versus being used as a FORMAT name because it would not have a period at the end of the name.

 

What does it mean when a variable is "uninitialized”?

This happens when you create a new variable and it has a missing value. You typically see this when you have a typo for your variable name.

 

When using formats, do you have to have the period after the name of the format?

When using the format name in a format statement or put statement, you must have the period. When you define your own format with the PROC FORMAT step, you don’t need the period in the name when you’re creating it, but anytime you use that format, whether it’s one you created or one of SAS’s formats, you have to have the required period because that’s the only way for SAS to differentiate the variable names from the format names. Keep in mind that the period can be specified 2 different ways, such as: COMMA10. (no decimal places) and COMMA10.2 (with 2 decimal places).

 

Is there a way to figure out the line # on the log mapping back to that of the code? I know it’s not correlated, but curious if that could be a cue to track down the error on the code, especially when code snippets are repeated in the code.

That really does become a tricky question. I would focus more on the code that’s highlighted and map the code that is highlighted and focus less on the line number. I would also focus more on the ERROR and WARNING messages and the structure of the log messages. Check out our documentation on Understanding he Log Structure for more insight on reading the log.

 

Is it possible to write a code that checks if the log has errors, then the code outputs the errors in a data?

You can save the results of the log as a file and use SAS to read the log. Some have written macro programs to do this. If you are interested in this, there is a great Ask The Expert coming up towards the end of the month that will address this question. Please come back for Why is the Log Report a Programmer’s Best Friend?

 

Is it bad to have a program with full quotes because in my case I have disciplined myself to always use double quotes?

No, that’s not bad at all. As you progress in your SAS skillset, you may start using the Macro Facility that requires double quotes so macro variable references can be resolved. If you get in the habit of using double quotes, it will make life a little easier when you start using the SAS Macro programming language.

 

This is not strictly a syntax error, but should we put a semi-colon after calling a macro? I noticed in SAS studio sometimes if I don't have this, it will throw off the color-coding for key words. But in base SAS editor, I usually do not see an issue if I don't put the semi-colon.

A macro call is not a macro statement and such it does not require a semi-colon. I have seen lots of programs that have a semi-colon after the macro call, but it’s not necessary and in some rare cases it could cause errors. We discuss this in detail in our SAS Macro Programming course. Note, however, that there are some Macro calls that do require an ending semi-colon, such as with stored processes, but those usages are well documented.

 

When exporting to Excel or CSV; whenever I try to leave the data in a sasbdat7 file it says to run on local. Is the best solution to land the SAS dataset on a file share - end users here cannot explicitly write to a SAS server, but they can write to a SAS server local file share location.

Questions like this really depend on the fitness of both SAS, Excel and your operating system and what components you have. This type of question is best answered by working with Tech Support. To open a track with Tech Support fill out the form at this link: http://support.sas.com/ctx/supportform/createForm

 

Can Davetta direct us to the correct location of "Format Code" in Enterprise Guide?  I'm unable to locate it. 

The Format Code icon looks the same in Enterprise Guide, as you see highlighted below from a screenshot of my Enterprise Guide 8.2 session.

wreeves_0-1617135155219.png

 

What is the name of the follow up webinar again?

Why is the Log Report a Programmer’s Best Friend?

 

You can also put "user" messages to the log.  put 'USER: More than 10 students in database now. Notify management.';

The PUT statement allows you to write user messages in the log.  However, USER: does not have a special color coding meaning to SAS. The message will show up in Black text with the word USER: in capital letters.  But it won’t have special color coding. But this is indeed a good way to write a customized message that you can locate easily in your log. If you want it to stand out more, you can change it to put “WARNING: USER: More than 10 students in database now. Notify management.”;

 

I have used "OPTIONS OBS=0 NOREPLACE;" when checking for any syntax issues without processing the data.  Is there anything to watch out for with this approach?

That’s a pretty slick way to do that.  The NOREPLACE option will prevent the data set from being overwritten with 0 observations. The only thing to watch for is to make sure you reset OBS= back to MAX when you are ready to execute the code and create a data set. Also, Enterprise Guide has an interactive Data step debugger that is useful when debugging a data step.

 

Why does PROC SQL sometimes not need the CALCULATED clause with a new variable? My guess is that this occurs when a new variable is created with no change to the actual value of the variable, but is essentially just a name change?  Example: test_var AS test_var_txt

The clauses in a PROC SQL step are not executed sequentially like the Data step. The order of the execution is the FROM, WHERE, SELECT, GROUP BY, HAVING, then ORDER BY, so if a column has already been created when the SELECT is executed, the remaining clauses that use the calculated column don’t need the CALCULATED keyword.

 

Can she show her putlog code again? I missed the data step near it.

Davetta will create a .zip file and include the program with the PUTLOG statements. She has named the file NotesWarningErrors.sas.

 

How do you fix W.D format in the log?

W.D is a standard numeric format, where W is the total width of the value you want displayed and the D is the number of decimal places. You can read more about the W.D format in the documentation here.

 

What does the error message "The table cannot be opened because it does not contain any columns" mean?

When you write a Data step that doesn’t create any rows/observations or columns/variables, you get this error message. The reason why this is happening will need to be investigated further.

 

Is there no other color to put Custom message in the log so it does not interfere with Note, Error or Warning that system also uses?

No, these are the only colors that are used. Think of it this way, it’s a great way to create your own custom messages and have SAS keep up with them as if it’s a message generated by the system. Plus, users don’t have to worry about lots of custom colors that could have different meanings at different companies. It keeps the messaging consistent, across all SAS interfaces and logs.

 

Wrong Option Name, is it equivalent to invalid Data set Option or Statement Option in Syntax Errors? Is the Option Name either Dataset or Statement?

Yes, you could say a wrong option name is equivalent to an invalid Data set or statement options. 

 

Is it better to use University Edition vis a vis SAS OnDemand for offline use. Does it consume a lot of GB?

SAS® OnDemand for Academics is now the primary software choice for learners. Access to SAS University Edition will end Aug. 2, 2021; users will no longer be able to download it after Apr. 30, 2021. Check out SAS OnDemand for Academics today for free access to SAS for individual learners as well as university educators and students.

 

I get a sufficient memory error when I am trying to export the result to an excel spreadsheet. It will give me the observation amount which may be 13,000 records.  Is there something I can include in my code or it based on the sever setup?

The insufficient memory error is not a SAS specific issue. I did find a trouble shooting document online that may give you some ideas of why you are getting this message. You can also contact Tech Support and open a track by filling out the form at this link: http://support.sas.com/ctx/supportform/createForm

 

This doesn't have anything to do with this presentation. In SAS EG when writing code, I open the code and can see it to the left under Servers, how do I keep the folder from closing?

I know that in Enterprise Guide 8.1 the Server Files and Folders collapses when opening a data set and this issue was resolved in Enterprise Guide 8.2. Remember that while you may be working independently in Enterprise Guide, it was written so multiple users could be accessing the same location and files, so when it collapses it’s attempting to auto-refresh the folder, and for programs, I don’t think there is a way to avoid this. If this continues to happen, I suggest you contact SAS Tech support.

 

Do all the errors and fixes work for SAS Enterprise Guide as well?

Yes, all of the errors and fixes work for SAS Enterprise Guide as well. Enterprise Guide is a different interface you can use to write SAS code and to point and click to generate results, but the SAS code is the same SAS code you would write in either interface (SAS Studio or Enterprise Guide). The only fix that may be different in the SAS Windowing environment is the unbalanced quote issue. You can’t just add a matching balancing quote and resubmit the code to fix the problem.  You must submit the following code first:

 

*’; *";*/;RUN;QUIT;

 

This is the “wrapper code” that is being submitted in SAS Studio and SAS Enterprise Guide on your behalf to avoid the issue with unbalanced quotes.  But in SAS Windowing environment, you have to submit this code on your own first to balance the quotation issue, then fix the problem by adding the quote to the appropriate portion of the code and THEN resubmit the code.

 

Curious about how this works? Check out this resource:

This wrapper code programmatically balances the unbalanced quotation marks. If a ' (single quote) is needed the code above uses the '; to balance the unbalanced single quote and the rest of the code is a comment and is ignored.  If SAS needs a " (double quote) to balance the unbalanced double quote, it uses "; to balance the double quote and the rest of the code is a comment and is ignored. And often a RUN; or a QUIT; might be omitted at the end of your program, so the RUN;QUIT; statements will prevent procedures and DATA steps from hanging if there is no RUN or QUIT statement in your program as the very last statement to end the step.

 

Can I format my code "format code feature" so that the indent is 3 chars instead of 4 chars?  We have different protocol at work.

Yes, you can do this in SAS Studio. The default number of spaces to indent as you have noticed is 4. You can change this in SAS Studio by going to the More Applications icon (picture), select Preferences, the select Code and Log and change Tab width: field to the number of spaces you require, and make sure you use the scroll bar to go down to the bottom of the window and select Save.

 

wreeves_1-1617135155232.png

 

You can make the same changes in Enterprise Guide. Go to Tools > Options > SAS Programs > Editor Options > Change Tab Size > Select OK.

 

wreeves_2-1617135155248.png

 

 

Sometimes my log says "see log for details" - but there's no additional information. Where do I find these details?

Sometimes when the log no longer shows error messages it may be a result of running code with unbalanced quotes or an unbalanced character. I’ve seen this happen in the SAS windowing environment. You can try submitting the following code:

*';*";*/;RUN;QUIT;

 

Can I get more clarification on the format types and what they do?

FORMATS are instructions that tell SAS how to display your data values. There are SAS defined formats like DOLLAR8.(numeric format), $CHAR15. (character format). Or you can create your own FORMATS to display your specific data. To learn more, please take a look at User-defined formats or SAS Formats by Category in our documentation.

 

What does the line number in the log tell you?  Will SAS always tell you what line the error is?

As you may recall in the demo with the missing semi-colon, sometimes the line number that is displayed in the log does not highlight the code that contains the error, the error in the code is found one line above.

 

Is there the formatting feature in SAS enterprise Guide that is part of a UNIX system?

SAS Enterprise Guide is a client application that can be installed on Windows. Enterprise Guide communicates with SAS on the operating system where SAS is installed. The operating system can be UNIX, or Windows, or Z/OS (mainframe). If by formatting you mean formatting your code within SAS Enterprise Guide, you would format the code the same way in Enterprise Guide regardless of your operating system; there is a format code button. If you are asking about specific FORMATS for UNIX, please take a look at SAS Formats under UNIX.

 

Should you pay attention to the Note message in the log?

I would always suggest you read your log, NOTES, WARNINGS and ERRORS. Your notes can still give you valuable information. For example, if a note states it read 570 observations from a data set and you were expecting 1700, you may want to investigate why you are only reading 570 observations when you were expecting 1700. No matter what, always READ YOUR LOG!

 

We run SAS 9.4 at work and there is no format button. Is there a way to format code quickly in this system?

There are some line number commands that you can use to assist you with formatting the code in the SAS windowing environment. You can read more about Text-Editing Commands for SAS Windowing Environment in our documentation. For indentation, take a look at the (Command or the (( Command. Or you can also highlight your SAS code and select shift+TAB key to indent. Please check out this SAS Community SAS 9.4 Tab Shortcut post to learn more.  

 

What are great debug tools?

If you have SAS Enterprise Guide there is an interactive Data step debugger. Otherwise, in order to debug the Data step, you would need to use a series of PUTLOG statements to determine what is going on behind the scenes in your Data step code. There is no debugger for PROC steps. You would have to write the code, submit it and check the log to see what NOTEs, WARNINGs and ERRORs you get.

 

Can you show the format code button again? Is it available in other environments?

See Q&A segment at the end of the webinar. This question is answered at 56:40 into the on-demand recording. Yes, it’s available in SAS Enterprise Guide on the programming tab and in SAS Studio as shown in the demo. It’s not available in the windowing environment.

 

Does SAS offer any certifications? Where to get best training?

Here is information on SAS Certification. We also have some free training available and free practice certification exams.

 

Is the format option in the PC-SAS editor?

No, the format code icon is not an option in the SAS Windowing environment editor. Please read the question above “We run SAS 9.4 at work and there is no format button. Is there a way to format code quickly in this system? “ for the answer of how you can still format your code using Text-Editing Commands for SAS Windowing environment.

 

Is SAS making any efforts to provide more user-friendly error messages in the future?

I’m sorry, I don’t have an answer for that question. The more you make certain errors, the more comfortable you’ll become with reading the log and learn how to decipher the messages.

 

Is there a simple way to avoid "lock not available" error?

If one process starts before another process finishes, there’s a lock on the data set so you can’t write to it. There is a SAS System option called the filelockwait system option where you can tell it to wait a designated amount of time for a lock file to become available.

 

I find it infuriating that SAS keeps running a (possibly very long) program even when a syntax error is found, spewing out tables and tables of garbage data. What would you suggest to make SAS stop the program as soon a problem is found?

There are many different techniques you can use and they depend on your operating system (mainframe, Unix, Windows) and your SAS interface (JCL, EG, SAS Studio). You could post this question on the SAS Community Forum to find out how other users handle this issue or you can open a track with Tech Support for specific recommendations based on your system configuration.

 

 

Recommended Resources

Types of SAS Errors

Webinar: Why is the Log Report a Programmer’s Best Friend

SAS Education

SAS Programming Learning Path

SAS Certification Practice Exams

 

Want more tips? Be sure to subscribe to the Ask the Expert board to receive follow up Q&A, slides and recordings from other SAS Ask the Expert webinars.  

Version history
Last update:
‎03-30-2021 04:14 PM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Article Labels
Article Tags