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

I am using the below macro code(using it as i want the same variable name from 2 different dataset).

%macro EOex(inp=,testvar=);
data EO;
   set EOex.&inp.;
   EOTEST=upcase(cats(substr(&testvar,1,4),substr(&testvar,length(&testvar)-1)));
   EOCAT=upcase(scan(&testvar,1));
run;
%mend;
%EOex(inp=EO_incl,testvar=EOi_std);
%EOex(inp=EO_excl,testvar=EOe_std);

But if i use it then it will just give me the last call and not the set of 2 calls. How can i set them in the same program?

 

Any help

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

As I have mentioned on many occasions, macro code does not do anything, it is a text find and replace system.  So what do we do with the code you presented, we do a find and replace, so that code becomes:

data EO;
   set EOex.EO_incl;
   EOTEST=upcase(cats(substr(EOi_std,1,4),substr(EOi_std,length(EOi_std)-1)));
   EOCAT=upcase(scan(EOi_std,1));
run;
data EO;
   set EOex.EO_excl;
   EOTEST=upcase(cats(substr(EOe_std,1,4),substr(EOe_std,length(EOe_std)-1)));
   EOCAT=upcase(scan(EOe_std,1));
run;

Now what part of this actual executable code does not work the way you had intended?  Is it because you are overwriting EO in both the first and second calls to the macro?  

Also, you would again find your like is much simpler using industry standards - possibly CDISC SDTM due to this being inclusion/exclusion information, this way you would have all the data in one dataset, and the same code could run over just one dataset.  Even if not using that, you can simplfy your code 50% by:

data eo;
  set eoex.eo_incl (rename=(eoi_std=std))
        eoex.eo_excl (rename=(eoe_std=std));
  eotest=upcase(cats(substr(std,1,4),substr(std,length(std)-1)));
  eocat=upcase(scan(std,1));
run;

See, never a need to use macro.

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

As I have mentioned on many occasions, macro code does not do anything, it is a text find and replace system.  So what do we do with the code you presented, we do a find and replace, so that code becomes:

data EO;
   set EOex.EO_incl;
   EOTEST=upcase(cats(substr(EOi_std,1,4),substr(EOi_std,length(EOi_std)-1)));
   EOCAT=upcase(scan(EOi_std,1));
run;
data EO;
   set EOex.EO_excl;
   EOTEST=upcase(cats(substr(EOe_std,1,4),substr(EOe_std,length(EOe_std)-1)));
   EOCAT=upcase(scan(EOe_std,1));
run;

Now what part of this actual executable code does not work the way you had intended?  Is it because you are overwriting EO in both the first and second calls to the macro?  

Also, you would again find your like is much simpler using industry standards - possibly CDISC SDTM due to this being inclusion/exclusion information, this way you would have all the data in one dataset, and the same code could run over just one dataset.  Even if not using that, you can simplfy your code 50% by:

data eo;
  set eoex.eo_incl (rename=(eoi_std=std))
        eoex.eo_excl (rename=(eoe_std=std));
  eotest=upcase(cats(substr(std,1,4),substr(std,length(std)-1)));
  eocat=upcase(scan(std,1));
run;

See, never a need to use macro.

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
  • 1 reply
  • 602 views
  • 0 likes
  • 2 in conversation