BookmarkSubscribeRSS Feed
stataq
Quartz | Level 8

hello,

 

I have a silly question to ask. Is there any document that I can use to better understand the sas codes that are written in very brief way? (to be honest, I don't know the exact terms to describe this situation. Maybe following example can better explain the situation)

 

data want;
set have;
m1+5;
run;

  It looks like m1+5 in fact is m1=m1+5. I am not sure about that, but the output suggested that.

 

I am still new to sas. When I read suggestion from the posts, there are quite some lines that were written in such matter and I don't know for sure which value/variable that they were imply to. Is there any document on this aspect? 

 

Thanks.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

First, m1+5 is not in general the same as m1=m1+5, although in this case it might be.

 

I think your broader question is about documentation, when you come across a PROC or Function or Statement that you don't understand, you should look it up.

 

Documentation:

Alphabetical list of all SAS PROCs

Alphabetical list of all SAS Functions

Alphabetical list of all SAS Statements

--
Paige Miller
FreelanceReinh
Jade | Level 19

Hello @stataq,

 

The case of m1+5; is indeed a bit tricky to look up in an alphabetical list of language elements as it is one of the rare examples where the name of the statement is not part of the syntax. It is called sum statement, so you find it under the letter "S" in the Dictionary of SAS DATA Step Statements.

ChrisHemedinger
Community Manager

This is a great question, as SAS (and other programming languages) have idioms that users adopt and that are difficult to find as reference in the documentation. You see them in examples of other people's work, and many have been described in SAS conference papers or other articles. 

 

In practice, most programmers use a construct like:

x+1;

To mean x=x+1, and this is executed at every iteration of the DATA step loop. I recommend using the DATA step debugger (available in SAS Enterprise Guide or SAS Studio on Viya) to step through and see exactly what's going on. A common use case is a running total sum, like

data class;
 retain runningtotal_weight 0;
 set sashelp.class;
 runningtotal_weight + weight;
run;
 

But as others point out, there are other use cases.

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
Astounding
PROC Star

The best starting point to learn "brief" codes is to learn more about SAS procedures.  These are routines that are already written, already debugged, and well documented.  They often replace dozens of lines of code if you were to try to write something from scratch.

Take some common procedures:  FREQ, MEANS, FORMAT, even PRINT.  Read about them and play with them until you know more than twice as much as what you know now.  Procedures embody expert decisions about what functionality is important, and would be useful to have put into a shortened, easier-to-use form.

Just my two cents.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 578 views
  • 5 likes
  • 5 in conversation