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

Can someone please explain why CALL SYMPUTX('numobs', dsnobs, 'g') in line 60 of the following code works? It seems to me that, since the (NOBS=DSNOBS) SET statement option in line 62 comes after the STOP statement, it will never even be executed. So how is the macro variable NUMOBS ever set to 144?

 

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55 
56 * Program11.2.9.sas;
57 * Using the NOBS= option on the SET statement;
58 %macro numobs(dsn=);
59 data _null_;
60 call symputx('numobs', dsnobs, 'g');
61 stop;
62 set &dsn nobs=dsnobs;
63 run;
64 %mend numobs;
65 %numobs(dsn=sashelp.air)

NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.02 seconds


66 %put The number of observations in SASHELP.AIR is &numobs;
The number of observations in SASHELP.AIR is 144
67 
68 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
80 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Screen Shot 2017-02-01 at 8.09.25 PM.png

 

https://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#p00hxg3x8lwivc...

 

Tip At compilation time, SAS reads the descriptor portion of each data set and assigns the value of the NOBS= variable automatically. Thus, you can refer to the NOBS= variable before the SET statement. The variable is available in the DATA step but is not added to any output data set.

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Screen Shot 2017-02-01 at 8.09.25 PM.png

 

https://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#p00hxg3x8lwivc...

 

Tip At compilation time, SAS reads the descriptor portion of each data set and assigns the value of the NOBS= variable automatically. Thus, you can refer to the NOBS= variable before the SET statement. The variable is available in the DATA step but is not added to any output data set.

 

data_null__
Jade | Level 19

You can make this slightly more efficient by dropping all the variables in &DSN.

 

set &dsn(drop=_all_) nobs=dsnobs;

While the SET is never executed all the variables from &DSN are placed in the PDF by the data step compiler.

 

Do you really need this macro?  Usually the question is "does the macro have zero observations?" and knowing how many obs adds nothing.

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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