Hi Team,
Could you please explain me this progeam.
*What is the use of %global for the 3 variables
*what is dsid and rc??Are these like any other variable we create using %Let???or do they have any special meaning????
Also how does this code work for several datasets???
Thanks
%macro obsnvars(ds);
%global dset nvars nobs;
%let dset=&ds;
%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));
%put &dset has &nvars variable(s) and &nobs observation(s).;
%end;
%else
%put Open for data set &dset failed - %sysfunc(sysmsg());
%mend obsnvars;
%obsnvars(sasuser.houses)
Now I could be completly but seems like a homework question
%global - Refer macro documentation
DSID contains value returned by the open function (could stand for dataset ID, could have been called anything
RC as above - return code? from the close function
%macro can be called mulitple times by passing different Dataset names in using the DS
Barry
Hi Karun,
%global makes the macro variables you create global. It means that you can use them outside the macro.
no special meanings for disd and rc. You can try to use different names.
Now I could be completly but seems like a homework question
%global - Refer macro documentation
DSID contains value returned by the open function (could stand for dataset ID, could have been called anything
RC as above - return code? from the close function
%macro can be called mulitple times by passing different Dataset names in using the DS
Barry
Hi,
Thanks a lot to both of you.
Regards
Karun,
Linlin and Barry have already answered your questions but, given your question and the others you have asked, I think one of us ought to make an important comment.
The code you asked about was from an example in the documentation. Glad to see you are reading the documentation.
But don't expect all of the examples in the documentation to be totally thought out, generalizable anywhere solutions. They often are quite far from that.
As Linlin mentioned, some of the macro variables were made global so that they could be accessed outside of the macro. However, they weren't all initialized in the macro and the ones with return codes (like dsid and rc) are only local.
Thus, if the macro is called multiple times, then fails, the global variable values will retain the values from a previous call.
In short, question any examples that you don't fully understand and don't blindly take the documentation examples as Gospel.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.