Sas

Asked • 04/04/19

SAS - How to return a value from a SAS macro?

I would like to return a value from a SAS macro I created but I'm not sure how. The macro computes the number of observations in a dataset. I want the number of observations to be returned. %macro nobs(library_name, table_name); proc sql noprint; select nlobs into :nobs from dictionary.tables where libname = UPCASE(&library_name) and memname = UPCASE(&table_name); quit; *return nobs macro variable; &nobs %mend; %let num_of_observations = %nobs('work', 'patients'); Also, I would like the `&nobs` macro variable that is used within the macro to be local to that macro and not global. How can I do that?

1 Expert Answer

By:

Rick A. answered • 04/04/19

Tutor
5 (33)

Experienced SAS Professional

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.