Dear,
When i ran second data step i am getting errors. Is it possible to use 'i' values as macro variable as in second data step. Thank you.
data sdtmall1(keep=memname name);
set sdtmall;
if index(name,'SEQ')>0 or index(name,'IDVARVAL')>0;
run;
data one;
do i=1 to 69;
set sdtmall1;
call symputx('in&i.',memname);
call symputx('seq&i.',name);
output;
end;
run;
You cannot mix and match. Data step variables are data step variables, they are not macro variables. Macro variables are macro variables, they are not data step variables.
Much simpler approach, since variable I is a data step variable, and you are in a data step, then use variable I as a data step variable.
data _null_;
do i=1 to 69;
set sdtmall1;
call symputx(cats('in',i),memname);
call symputx(cats('seq',i),name);
/* output; */ <--- The output statement simply isn't needed here
end;
run;
Also note that indenting makes your code easier to read.
Thank you for the reply. I have one more issuethat i am not able to understand. Please help. Thank you.
After you code i am able to create macro variables, but i need to use the below macro code. why the data step is not running. Thank you
data _null_;
do i=1 to 3;
set sdtmall1;
call symputx(cats('in',i),memname);
call symputx(cats('seq',i),name);
%macro duplicates(in=,seq=);
proc sort data=sdtm.&in. out=_null_ dupout=dups__&in. nodupkey;
by usubjid &seq.;
run;
proc print data=dups__&in. width=min ;
title " Dups in sdtm.&in.";
var usubjid &seq.;
run;
%mend;
%duplicates(in=&ini.,seq=&seqi.);
end;
run;
Whenever you create a macro (or a macro variable) and use it, the result must be VALID SAS CODE.
So, you can't have a PROC SORT and PROC PRINT inside a data step. That is not valid SAS code.
In your code, you could call the macro %DUPLICATES after the RUN; that ends the data step. That would be LEGAL SAS CODE. Whether it is actually what you want or not, I don't know.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.