I'm converting a SAS code into STATA so it's more accessible to people at work.
The original SAS code is:
%IF (&YEAR GE 1998) %THEN %DO;
%LET ALSOKEEP=%STR(&ALSOKEEP BCALL BMAGZNEWS BMAILADTV BINTERNET
BFRIENDWORK BFINPRO BFINPLAN BSELF BDONT BOTHER
ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK
IFINPRO IFINPLAN ISELF IDONT IOTHER);
%END;
and what it's doing is adding more variable names to a macro ALSOKEEP.
In STATA, I've written this
#delimit;
if (`YEAR'>=1998) {;
local ALSOKEEP="`ALSOKEEP'"+" BCALL BMAGZNEWS BMAILADTV BINTERNET
BFRIENDWORK BFINPRO BFINPLAN BSELF BDONT BOTHER
ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK
IFINPRO IFINPLAN ISELF IDONT IOTHER";
};
#delimit cr
And the problem is, because the list of additional variables is in a quote, the formatting (line change and indentation) is also saved in the macro, when what I want is just a long line of code that the computer takes in. For instance, this is what is saved into ALSOKEEP.
Y1 YY1 SAVED BCALL BMAGZNEWS BMAILADTV BINTERNET BFRIENDWORK BFINPRO BFINPLAN BSEL
> F BDONT BOTHER ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK
> IFINPRO IFINPLAN ISELF IDONT IOTHER
where Y1 YY1 SAVED is the original value of ALSOKEEP that the long string was added to. You see, there is indentation between each line instead of one space. The best alternative I've thought of that would keep the code readable and formatted right is this:
#delimit;
if (`YEAR'>=1998) {;
local ALSOKEEP="`ALSOKEEP'"+" BCALL BMAGZNEWS BMAILADTV BINTERNET"
+" BFRIENDWORK BFINPRO BFINPLAN BSELF BDONT BOTHER"
+" ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK"
+" IFINPRO IFINPLAN ISELF IDONT IOTHER";
};
#delimit cr
but it looks rather messy and requires more work as I have many of these (much longer) to repeat.
Also, if possible, I'd appreciate a solution where I don't need to use delimiters. Universal delimiter use in my code was causing problem with declaring local macros, so now I'm spot-using it.
Thanks in advance.
The original SAS code is:
%IF (&YEAR GE 1998) %THEN %DO;
%LET ALSOKEEP=%STR(&ALSOKEEP BCALL BMAGZNEWS BMAILADTV BINTERNET
BFRIENDWORK BFINPRO BFINPLAN BSELF BDONT BOTHER
ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK
IFINPRO IFINPLAN ISELF IDONT IOTHER);
%END;
and what it's doing is adding more variable names to a macro ALSOKEEP.
In STATA, I've written this
#delimit;
if (`YEAR'>=1998) {;
local ALSOKEEP="`ALSOKEEP'"+" BCALL BMAGZNEWS BMAILADTV BINTERNET
BFRIENDWORK BFINPRO BFINPLAN BSELF BDONT BOTHER
ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK
IFINPRO IFINPLAN ISELF IDONT IOTHER";
};
#delimit cr
And the problem is, because the list of additional variables is in a quote, the formatting (line change and indentation) is also saved in the macro, when what I want is just a long line of code that the computer takes in. For instance, this is what is saved into ALSOKEEP.
Y1 YY1 SAVED BCALL BMAGZNEWS BMAILADTV BINTERNET BFRIENDWORK BFINPRO BFINPLAN BSEL
> F BDONT BOTHER ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK
> IFINPRO IFINPLAN ISELF IDONT IOTHER
where Y1 YY1 SAVED is the original value of ALSOKEEP that the long string was added to. You see, there is indentation between each line instead of one space. The best alternative I've thought of that would keep the code readable and formatted right is this:
#delimit;
if (`YEAR'>=1998) {;
local ALSOKEEP="`ALSOKEEP'"+" BCALL BMAGZNEWS BMAILADTV BINTERNET"
+" BFRIENDWORK BFINPRO BFINPLAN BSELF BDONT BOTHER"
+" ICALL IMAGZNEWS IMAILADTV IINTERNET IFRIENDWORK"
+" IFINPRO IFINPLAN ISELF IDONT IOTHER";
};
#delimit cr
but it looks rather messy and requires more work as I have many of these (much longer) to repeat.
Also, if possible, I'd appreciate a solution where I don't need to use delimiters. Universal delimiter use in my code was causing problem with declaring local macros, so now I'm spot-using it.
Thanks in advance.
Comment