Macro creation while skipping quotes
Macro creation while skipping quotes
(OP)
I have some SAS macros that need to be created. These macros are used as file descriptions for Excel files. The macros are derived from fields in files that are input to the program. Unfortunately all these fields exist as character fields and I need to strip the leading and trailing quotes from these fields when creating the macro. The field lengths are not known, is there a way to do this?
Example:
%MODEL(CLIENT = 'TECH', REPORT_SEGMENT = 'TOTAL', PRIOR_ANALYSIS_YEAR = 'ANY', SVCDTE1_PRIOR = '2001-01-01', TIME_CODE = 'ANNUAL');
Needs to be converted to
&CLIENT should be TECH not 'TECH' etc.
so when the excel file is created
c:\TEMP\MODEL(&CLIENT.)(&REPORT_SEGMENT.)(&TIME_CODE.).xls it will be without the quotes for the macros.
Thanks,
Example:
%MODEL(CLIENT = 'TECH', REPORT_SEGMENT = 'TOTAL', PRIOR_ANALYSIS_YEAR = 'ANY', SVCDTE1_PRIOR = '2001-01-01', TIME_CODE = 'ANNUAL');
Needs to be converted to
&CLIENT should be TECH not 'TECH' etc.
so when the excel file is created
c:\TEMP\MODEL(&CLIENT.)(&REPORT_SEGMENT.)(&TIME_CODE.).xls it will be without the quotes for the macros.
Thanks,
Michael
RE: Macro creation while skipping quotes
Functions that I know would help:
Index($tring, $part) - returns where $part is within $tring
Left($tring) - left justifies the charactr string
Length($tring) - gives you the length of the string
Translate($tring,$to,$from) - changes all occurances of $from to $to within the input string
Compress($tring,$remove) - takes all occurances of $remove from $tring
Trim($tring) - removes trailing blanks
Verify($tring, $part) - finds the first occurance of $part within $tring
You can even embed these within each other - so Length(trim($string)) or substr($tring, 1, Verify($string, "'")-1)
I have even used the function QUOTE($tring) to have SAS put quotes around the whole string.
If you show me the varaiables that you are using to make the desired output string, I am sure we can figure it out.
RE: Macro creation while skipping quotes
Example &Client comes in as 'TECH', I would need a new macro called RClient which changes that to TECH.
Thanks,
Michael
RE: Macro creation while skipping quotes
%let oldvar = 'tech';
%let newvar = %substr(&oldvar, 2, %length(&oldvar)-2);
%put &newvar ;
will display
tech
Michael
RE: Macro creation while skipping quotes
RE: Macro creation while skipping quotes
%let oldvar = 'TECH';
%let newvar = %SYSFUNC(compress(&oldvar, "'"));
%SYSFUNC executes SAS language functions or user-written functions within the macro facility.
RE: Macro creation while skipping quotes