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 .........

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 8 replies
  • 1044 views
  • 0 likes
  • 3 in conversation