BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

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

8 REPLIES 8
Reeza
Super User

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. 

 

Ksharp
Super User

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)

 

pawandh
Fluorite | Level 6
No it is not a job interview question.:)
here vmember is a data set name?
Ksharp
Super User
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.
Ksharp
Super User
%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 

pawandh
Fluorite | Level 6
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
Ksharp
Super User
Sorry. It is a VIEW . while dictionary.members is a TABLE .
Ksharp
Super User
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 .........

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2098 views
  • 0 likes
  • 3 in conversation