- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi -
I am a long time SAS user but there are still some things I don't understand. When using nobs to count observations, as in
data _NULL_;
if 0 then set sashelp.cars nobs=n;
put "no. of observations =" n;
stop;
run;
why is the syntax "nobs = n" instead of "n = nobs"? Any other time we want to create a new variable, we put the name of the variable on the left of the equal sign and the value on the right. Here it's the opposite. Can someone explain this to me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The option in the SET command is NOBS=variablename. This is consistent with the way other options in the SET command work.
If you type
if 0 then set sashelp.cars n = nobs;
you get an error, as there is no option in the SET command that is N=
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are confusing two totally different things. Both of which are common things to do in SAS.
In this statement:
set sashelp.cars nobs=n;
NOBS is the name of an option that the SET statement supports. The equal sign separates the option name from the value being given for the option. This particular option wants the NAME of a variable. It will then populate that variable with the number of observations in the dataset.
These statements:
nobs=n;
n=nobs;
z=y+x;
index=1;
Are assignment statements. The are used in data steps (and some PROCs that support coding).
The name of the variable that is being assigned the value comes first. The equal sign indicates that is an assignment statement. And everything after the equal sign is the expression that resolves to the value to be assigned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! This makes sense.