BookmarkSubscribeRSS Feed
Barite | Level 11


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;
Diamond | Level 26

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

 Also note that indenting makes your code easier to read.

Paige Miller
Barite | Level 11



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;



Diamond | Level 26

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.

Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1 like
  • 2 in conversation