BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

plz find & remove the

 

 

%let dsName=;
57 options nomprint nomlogic;
58
59 %macro check(dsName= );
60
61 %let dsid = %sysfunc(open(&dsName, IS));
62
63 %if &dsid = 0 %then %put %sysfunc(sysmsg());
64
65 %let nlobs = %sysfunc(attrn(&dsid,NLOBS));
66
67 %put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);
68
69 %let rc = %sysfunc(close(&dsid));
70
71 %mend;
72
73 %check(dsName=);
ERROR: There is not a default input data set (_LAST_ is _NULL_).
WARNING: Argument 1 to function ATTRN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set
to a missing value.
9 REPLIES 9
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You have not provided a dataset in the parameter to the macro call:

%check(dsName=);

                            ^

This is invalid as open needs a valid dataset.  As you have gone ahead with this solution, you will need to include further code at the beginning of the macro to ensure that the dataset is valid and exists, i.e.

%if %sysfunc(exists(&dsname.)) %then %do;

  your macro code

%end;

%else %do;

  %put Dataset &dsname. does not exist;

%end;

 

Or, your could just not use macro code at all and go with:

proc sql noprint;
  select  NOBS 
  into    NUMOBS
  from    DICTIONARY.TABLES 
  where   LIBNAME="SASHELP"
    and   MEMNAME="CLASS";
quit;

As there is almost never a "need" to do things in macro language.

 

 

 

 

RTelang
Fluorite | Level 6
%let dsName=;
options nomprint nomlogic;

%macro check(dsName= );

%let dsid=%sysfunc(open(&dsName, IS));

%if &dsid=0 %then %put %sysfunc(sysmsg());

%let nlobs= %sysfunc(attrn(&dsid,NLOBS));

%put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);

%let rc= %sysfunc(close(&dsid));

%mend;

%check(dsName=)

add ?? where?? show..
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Here, in my post, where the upward point triangle is, you need to put a dataset (with library if not work);

%check(dsName=);

                            ^

 

E.g. 

%check(dsName=sashelp.class);

 

                            

RTelang
Fluorite | Level 6
basically i need a macro to display number of observations in a dataset for eg dsname=100
RTelang
Fluorite | Level 6
can u rectify my cod e& give me -thanks
RTelang
Fluorite | Level 6
%let dsName=;
57 options nomprint nomlogic;
58
59 %macro check(dsName= );
60
61 %let dsid=%sysfunc(open(&dsName, IS));
62
63 %if &dsid=0 %then %put %sysfunc(sysmsg());
64
65 %let nlobs= %sysfunc(attrn(&dsid,NLOBS));
66
67 %put No of Observation in dataset %trim(&dsName) : %trim(&nlobs);
68
69 %let rc= %sysfunc(close(&dsid));
70
71 %mend;
72
73 %check(dsName=work.data1);
ERROR: File WORK.DATA1.DATA does not exist.
WARNING: Argument 1 to function ATTRN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set
to a missing value.
No of Observation in dataset work.data1 : . getting this error what to do??
RW9
Diamond | Level 26 RW9
Diamond | Level 26

In your library WORK, there is no dataset called DATA1.  This is what the log message is telling you.  The macro will only work on a dataset which exists in the library given.  So open SAS, find a dataset, if there is nothing in your WORK library, then look at SASHELP.  Take the CLASS dataset as an example from there and replace work.data1 in your example with sashelp.class.

Rikard
Fluorite | Level 6

If you need a macro that gives you the number of rows in a table, the minimum input to this macro needs to be the name of a specific table for which you want the number of rows.

E.g. 

%check(dsName=sashelp.class);

You suggest a solution where you would like to to supply "dsName=100". What kind of input is the value 100? How will this input be used to give you the number of rows in a table?

 

Perhaps you are not yet familiar with macro functionality and how to call a macro? Then I suggest some reading. E.g.

Introduction to the Macro Facility

FreelanceReinh
Jade | Level 19

Hi @RTelang,

 

If you just "need a macro to display number of observations in a dataset" (as you say) or a macro for some other day-to-day task, you can resort to existing macros on the web. Why reinvent the wheel? For example, have a look at Roland's SAS® Macros. This website also contains many tips and tricks for writing your own macros from the author of this large macro collection, Roland Rashleigh-Berry (a former colleague of mine).

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9 replies
  • 3486 views
  • 1 like
  • 4 in conversation