BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
struppi1979
Calcite | Level 5

Hey guys,

 

i wrote this small Macro . It compares two Datasets.

 

at the Point %comp(XXX,PatientOID);  i will use for the call of the Dataset names the content of a variable, line by line, instead off. 

There are many datasets to compare and i wrote the Dataset names with DIRLIST into a variable.

 

I hope you will understand me... THANKS A LOT

 

%macro comp(ds=,id=); 

proc sort data=p3465_n.&ds out=&ds._new;
     by &id; 
run;
proc sort data = p3465_o.param_&ds out=&ds;
     by &id;
run;

title "---- Compare proc contents of &ds  -----";
proc compare base=&ds._new comp=&ds listall maxprint=(3200,3200);
 id &id;
 *where visitnum<50;
run;
title;

%mend;



%comp(XXX,PatientOID);
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Do you mean you want to generate code something like this:

 

 

%comp(datasetname1,PatientOID)

%comp(datasetname2,PatientOID)

%comp(datasetname3,PatientOID)

...

 

UNTESTED CODE

 

proc sql noprint;
    select distinct memname into :names separated by ' ' from dictionary.tables
        where upcase(libname)='P3465_N';
quit;

%macro dothis;
     %do i=1 %to %sysfunc(countw(&names));
         %let thisname=%scan(&names,&i,%str( ));
         %comp(&thisname,PatientOID)
      %end;
%mend;
%dothis
--
Paige Miller

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

And what is the question?

struppi1979
Calcite | Level 5

… ok:

this is the Macro Call. 

 

%comp(XXX,PatientOID);

 

and in the Variable 'both'  in the Field varname there stand the variable names.

 

i need a help to paste the variable names automatically to XXX.

PaigeMiller
Diamond | Level 26

Do you mean you want to generate code something like this:

 

 

%comp(datasetname1,PatientOID)

%comp(datasetname2,PatientOID)

%comp(datasetname3,PatientOID)

...

 

UNTESTED CODE

 

proc sql noprint;
    select distinct memname into :names separated by ' ' from dictionary.tables
        where upcase(libname)='P3465_N';
quit;

%macro dothis;
     %do i=1 %to %sysfunc(countw(&names));
         %let thisname=%scan(&names,&i,%str( ));
         %comp(&thisname,PatientOID)
      %end;
%mend;
%dothis
--
Paige Miller
struppi1979
Calcite | Level 5

yes, … perhaps as a macro that takes eack new Observation of both and writes it as datasetname1,datasetname2 ...

PaigeMiller
Diamond | Level 26

Message #4 updated to include code.

--
Paige Miller
gamotte
Rhodochrosite | Level 12

Hello,

 

Do you want to use a reference dataset to generate macro calls ?

If so, here is a way to achieve this :

 

%macro comp(ds=, id=);

    %put &=ds. &=id.;

%mend;

data meta;
    input ds_name $ var_id $;
    cards;
foo x
bar y
baz z
    ;
run;

data _NULL_;
    set meta;
    call execute(cats('%comp(ds=',ds_name,', id=',var_id,');'));
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1080 views
  • 1 like
  • 4 in conversation