macros

Reply
Contributor
Posts: 59

macros

have to dipslay the datasets starting with name P

 


proc sql;
select distinct memname into : ab separated by ',' from
dictionary.columns where libname='work' and upcase(memname) like"P%";
%let r=&sqlobs;
quit;

 

%put &ab &r;

(P1,PATIENT,PAWAN,PAWAN1,PP,PULMICORT_PA,PULMICORT_PH 7)

 

 

 


%macro b(libname);
%do i= 1 %to &r;

proc print data=&libname..%scan(&ab,&i);
run;
%end;
%mend;
%b(work);

getting error  -

ERROR: Macro function %SCAN has too many arguments. The excess arguments will be ignored.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
is required. The condition was: PATIENT
ERROR: Argument 2 to macro function %SCAN is not a number

Super User
Posts: 17,737

Re: macros

If a macro variable parameter has comma's how does SAS know which is part of the macro %scan, and which is part of the macro variable. Try using a different delimiter for your macro variable list. 

 

Super User
Posts: 9,662

Re: macros

[ Edited ]

It is a job interview question for some CRO corporation ?

 

 

%macro b(libname);
data _null_;
 set sashelp.vmember(where=(libname="%upcase(&libname)" and upcase(memname) like "P%"));
 call execute(cats('proc print data=',libname,'.',memname,';run;'));
run;
%mend;
%b(work)

 

Contributor
Posts: 59

Re: macros

No it is not a job interview question.Smiley Happy
here vmember is a data set name?
Super User
Posts: 9,662

Re: macros

it could VIEW or CATALOG , any sas member. if you only want TABLE add another option datatype='data' . If your libname only contain TABLE, that is not a question.
Super User
Posts: 9,662

Re: macros

[ Edited ]
%macro b(libname);
data _null_;
 set sashelp.vmember(where=(libname="%upcase(&libname)" and upcase(memname) like "P%" and memtype='DATA'));
 call execute(cats('proc print data=',libname,'.',memname,';run;'));
run;
%mend;
%b(work)

Updated 

Contributor
Posts: 59

Re: macros

sorry but not able to understand ...here v r copying the data from sashelp library(set sashelp) then how v can give this libname condition as already v have defined the library..Plz explain
Super User
Posts: 9,662

Re: macros

Sorry. It is a VIEW . while dictionary.members is a TABLE .
Super User
Posts: 9,662

Re: macros

You can use this view as a table (dictionary.members) at anywhere, most likely in data step . This view can use other data set option too like KEEP DROP .........
Ask a Question
Discussion stats
  • 8 replies
  • 449 views
  • 0 likes
  • 3 in conversation