Wenling,
You need a macro, unless you like to type. SASHELP is your friend. I assume that -1 is an example. I did not assume that the variable would only be char. The following is untested:
%macro id_minus_one
( path =
, vars = patientid
id
sampleid
, value = -1
) ;
%if %nrbquote(&path.) = %str()
%then
%do ;
%put WAR%str(NING): path is a required parameter. ;
%goto __END ;
%end ;
%if %sysfunc( fileexist( &path. )) = 0
%then
%do ;
%put WAR%str(NING): Path does not exist: &path. ;
%goto __END ;
%end ;
libname lib
"&path."
access = readonly
;
/**************************************************/
proc sql noprint ;
select memname
, upcase( name )
, type
into : ds1 - : ds999
, : var1 - : var999
, : t1 - : t999
from sashelp.vcolumn
where upcase( libname ) = "LIB"
and upcase( name ) in
( "%sysfunc( prxchange( s/\s+/%str(%" , %")/ , -1 , %upcase(&vars.)))" )
;
quit ;
%do __i = 1 %to &sqlobs. ;
%let __j = 1 ;
%let v = %scan( &vars. , &__j. , %str()) ;
%do %while ( &v. ne ) ;
proc sql ;
create table var as
select distinct "&&&ds&__i." as Dataset
length = 32
, "&&&var&__i." as Variable
length = 32
, "&&&t&__i." as Type
from lib.&&&ds&__i.
where &&&var&__i. = %if &&&t&__i. = char %then "&value." ;
%else &value. ;
;
quit ;
proc append
base = id_minus_1
data = var
;
run ;
proc datasets
library = WORK
NoList
;
delete var ;
quit ;
%let __j = %eval( &__j. + 1 ) ;
%let v = %scan( &vars. , &__j. , %str()) ;
%end ;
%end ; /* CYCLE THROUGH __i */
%__END:
%mend id_minus_one ;
%id_minus_one
( path = C:\TEST ) ;
Good luck,
Kevin
PS Formatting is an issue on SAS Communities. Check the code carefully, becuase parts may have been lost in the transfer/formatting.