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
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.
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.
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.
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.