Hi everyone.
I have perhaps simple question but I stacked with this code and I don't know how to correct it.
I have a variable called "zm". And I want to create a new variable (zm2) based on this first one. I tried a few codes like this below but not one of them works.
%let zm = yrbrn edlvdee isco08 blgetmg;
%let zm2 = %sysfunc(tranward(&zm, "isco08", "iscogrp"));
%put &zm2;
I want to receive something like that:
zm2 = yrbrn edlvdee ISCOGRP blgetmg;
Could anyone help me?
tranWARD is not a function. Don't use " ";
4 %let zm = yrbrn edlvdee isco08 blgetmg;
5 %let zm2 = %sysfunc(transtrn(&zm,isco08,iscogrp));
6 %put &=zm2;
ZM2=yrbrn edlvdee iscogrp blgetmg
tranWARD is not a function. Don't use " ";
4 %let zm = yrbrn edlvdee isco08 blgetmg;
5 %let zm2 = %sysfunc(transtrn(&zm,isco08,iscogrp));
6 %put &=zm2;
ZM2=yrbrn edlvdee iscogrp blgetmg
Seems to me that the quotes are needed inside the transtrn function.
@PaigeMiller wrote:
Seems to me that the quotes are needed inside the transtrn function.
Not when using with SYSFUNC on macro variables. Unless the quotes are part of the string you want to change. Notice how this doesn't work.
7 %let zm = yrbrn edlvdee isco08 blgetmg;
8 %let zm2 = %sysfunc(transtrn(&zm,"isco08","iscogrp"));
9 %put &=zm2;
ZM2=yrbrn edlvdee isco08 blgetmg
Guru, Nice example to understand how tokenisation works especially when literal tokens are processed by the word scanner , then resolved by the macro processor and eventually sent to compiler for execution. Kudos!
Could you tell me also how to delete a word from string?
If I use this function then I get an extra space in the variable and I don't want that. Is there any other way?
%let zm_obj3 = %sysfunc(transtrn(&zm_obj2,eduyrs,));%put &zm_obj3;yrbrn edlvdee hhmmb iscogrp hinctnta rlgdgr rlgdnm stflife domicil inprdsc blgetmg
@Margrett wrote:
Could you tell me also how to delete a word from string?
If I use this function then I get an extra space in the variable and I don't want that. Is there any other way?
%let zm_obj3 = %sysfunc(transtrn(&zm_obj2,eduyrs,));%put &zm_obj3;yrbrn edlvdee hhmmb iscogrp hinctnta rlgdgr rlgdnm stflife domicil inprdsc blgetmg
Your target does not include the blank so you are getting what you asked for. You could use COMPBL after TRANSTRN or add a space to the target.
141 %let zm = yrbrn edlvdee isco08 blgetmg;
142 %let zm2 = %sysfunc(transtrn(&zm,%str(isco08 ),));
143 %put &=zm2;
ZM2=yrbrn edlvdee blgetmg
I'm a bit worried that you are doing this macro string manipulation when you should be using different tools. Can you start a new question where you ask a more fundamental question related to your overall goal.
Thank you for your help. I'm doing a project for logistic regression for my university classes. It's more about results than code itself but I wonder how can I automatize the code in few places rather than manually rewrite variables etc. So it is good. I don't need more. Thank you for your time and help. 🙂
%let zm = yrbrn edlvdee isco08 blgetmg; %let zm2 = %sysfunc(tranwrd(&zm, isco08, iscogrp)); %put &zm2;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.