66 %if &dsid ne 0 %then %sysfunc(attrn(&dsid,&attribute));
What you try to do in this line?
You are using attrn with wrong attr-name ? chk : ATTRN Function valid attr-name
Where is varnum in your code?
In which variable you will keep the %sysfunc(); values? I think you are missing a %let in this line.....
If you are going to use ATTRN Function
Then you need to use valid attr-name with it in the second argument like NOBS, ANY ........ other mentioned on the link above
So for example your code may look like:
%if &dsid ne 0 %then %put %sysfunc(attrn(&dsid,nobs));
I also think once you fix the attribute parameter in the attrn() function, you will get a syntax error at line 67 with "%else ¬found;". Are you trying to put the notfound macro variable into another variable, or are you trying to print the value of the notfound macro variable to the log? If you leave it as is, the code will resolve to %else . or %else ' ', depending on the value of the type macro variable. SAS will read this and give you a syntax error.
If you are wanting to print the value of the notfound macro variable to the log, you will need to add a "%put" in front of the ¬found. If you are wanting to put the value of the notfound macro variable into another variable or a data set, you will need to add another %let statement setting a variable equal to ¬found or have a data step with the variable notfound put into a field. Hope this helps!
When you say "variable attribute", do you mean the variable type (Character/Numeric), Length, Format, etc..? You could always run a proc contents and output it to a data set and limit that data set by the NAME value for whatever variable you are looking for. Then you could set some macro variables equal to some of the different values in the data set for that variable and print those to the log. Is that something you are trying to accomplish?
So, using the attrn() function, there are many different "attr-names" you can use in the second argument of the function. You currently have nobs hardcoded to return which specifies the number of physical observations. You could add an additional parameter in your %macro statement to set whatever attr-name you want to use with the attrn() function. The statement would change to "%macro datatt(data=, attribute=, type=, notfound=, attrname=);". All the different types of attributes you can find at the following link: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212040.htm
I would modify the nobs in the second argument of the attrn() function and set it equal to "&attrname". Then in your call of the datatt macro, if you wanted to display nobs, you just call it like "%datatt(data=sashelp.class, attribute=age, type=n, notfound=, attrname=nobs);".
Change the "&&attrname" to "&attrname". Also, you need to include the notfound and attrname parameters in the %macro statement. Instead of "%macro datatt(data=,attribute=,type=);", try doing "%macro datatt(data=,attribute=,type=,notfound=,attrname=);". That should fix those errors.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.