Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro Error Message 1

Status
Not open for further replies.

Dunnes

MIS
Sep 30, 2009
4
GB
Hi,
i have recently moved from SAS 9.2 to 9.13 adn some of my code wont work any more. I have quite a large macro and i get an error message on the first instance of a few let functions.

Code:

data QSI_WealthSGout;
set wealthselfgenapp;
where BranchID eq &id;
run;
%let WealthSGrows=%eval(%nobs(QSI_WealthSGout)+4);


Error Message:

WARNING: Apparent invocation of macro NOBS not resolved.
WARNING: Apparent invocation of macro NOBS not resolved.
ERROR: Required operator not found in expression: %nobs(QSI_WealthSGout)+4
ERROR: The macro CREATEBOOKS will stop executing.

im thinking it may not recognise %nobs on the first loop but am slightly cluless as to why it doesnt work in a different version of SAS

Any help would be great
Cheers
Mike
 
I'm guessing you are trying to get the number of obs?

If so, check this out:

Macro function


Code:
%macro obsnvars(ds);
       %global dset nvars nobs;
       %let dset=&ds;
       %let nvars = 0;
       %let nobs  = 0;
       %let dsid = %sysfunc(open(&dset));
       %if &dsid %then   %do;
           %let nobs =%sysfunc(attrn(&dsid,nobs));
           %let nvars=%sysfunc(attrn(&dsid,nvars));
           %let rc = %sysfunc(close(&dsid));
           %end;
       %else   %do;
           %put open for data set &dset failed - %sysfunc(sysmsg());
              %let nobs = -9999999;
           %end;
       %Put ;
       %Put &dset has &nobs observation(s) and &nvars variable(s).;
%mend obsnvars;

To call:


Code:
%obsnvars(EXTRACT.data1);

&nobs is the macro variable.

I often use that to create loops. I.e. 1 to &nobs
 

excellent thanks for your help. I believe that this macro must have been defined befroe but when i moved systems it needed to be added to the catalog. Thanks for the code sorted now

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top