DATA Step, Macro, Functions and more

how to update the dataset with the new macro call

Accepted Solution Solved
Reply
Highlighted
Regular Contributor
Posts: 214
Accepted Solution

how to update the dataset with the new macro call

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


Accepted Solutions
Solution
‎03-08-2018 07:32 AM
Super User
Super User
Posts: 9,599

Re: how to update the dataset with the new macro call

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


All Replies
Solution
‎03-08-2018 07:32 AM
Super User
Super User
Posts: 9,599

Re: how to update the dataset with the new macro call

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 86 views
  • 0 likes
  • 2 in conversation