- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%if &dsid ne 0 %then %sysfunc(attrn(&dsid,&attribute));
& having issue solving this errorthis attarn
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%local dsid;
%if %length(&type)= 0 %then %let type= N;
%else %let type = %upcase(%substr(&type,1,1));
%if &type = N %then %let notfound = .;
%else %let notfound = ' ';
%let dsid = %sysfunc(open(&data));
%if &dsid ne 0 %then
%put %sysfunc(attrn(&dsid,nobs));
%else
%put ¬found;
%let dsid = close(&dsid);
%mend datatt;
%datatt(data =work.test0,attribute =var3,type =N,notfound =.); hello this is my code but it doesn't display variable attribute what changes do i do to display a attribute of a specified dataset variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
My code only giving the number of attribute in d log how can i modify it to display a specific attribute of a specified data-set variable....?
%macro datatt(data = ,
attribute =,
type=);
%local dsid;
%if %length(&type)= 0 %then %let type= N;
%else %let type = %upcase(%substr(&type,1,1));
%if &type = N %then %let notfound = .;
%else %let notfound = ' ';
%let dsid = %sysfunc(open(&data));
%if &dsid ne 0 %then
%put %sysfunc(attrn(&dsid,nobs));
%else
%put ¬found;
%let dsid = close(&dsid);
%mend datatt;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
56 %macro datatt(data = ,
57 attribute =,
58 type=);
59 %local dsid;
60
61 %if %length(&type)= 0 %then %let type= N;
62 %else %let type = %upcase(%substr(&type,1,1));
63 %if &type = N %then %let notfound = .;
64 %else %let notfound = ' ';
65
66 %let dsid = %sysfunc(open(&data));
67 %if &dsid ne 0 %then
68 %put variable=%sysfunc(attrn(&dsid,&&attrname));
69 %else
70 %put ¬found;
71 %let dsid = close(&dsid);
72
73 %mend datatt;
74 %datatt(data=sashelp.class, attribute=age, type=n, notfound=., attrname=nobs);
ERROR: The keyword parameter NOTFOUND was not defined with the macro.
ERROR: The keyword parameter ATTRNAME was not defined with the macro.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
56 %macro datatt(data=,
57 attribute=,
58 type=,
59 notfound=,
60 attrname=);
61 %local dsid;
62
63 %if %length(&type)= 0 %then %let type= N;
64 %else %let type = %upcase(%substr(&type,1,1));
65 %if &type = N %then %let notfound = .;
66 %else %let notfound = ' ';
67
68 %let dsid = %sysfunc(open(&data));
69 %if &dsid ne 0 %then
70 %put variable=%sysfunc(attrn(&dsid,&attrname));
71 %else
72
73 %put ¬found;
74 %let dsid = close(&dsid);
75
76 %mend datatt;
77 %datatt(data=sashelp.class, attribute=, type=n, notfound=., attrname=nvars);
variable=5--->
a specific variable name should be displayed..
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content