Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro creation while skipping quotes 1

Status
Not open for further replies.

Queryman

Programmer
Nov 4, 2002
243
US
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,


Michael

 
Maybe I am missing something here...
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.
 
Hi, The variable are in my email above.
Example &Client comes in as 'TECH', I would need a new macro called RClient which changes that to TECH.
Thanks,

Michael

 
I figured it out

%let oldvar = 'tech';
%let newvar = %substr(&oldvar, 2, %length(&oldvar)-2);
%put &newvar ;

will display
tech


Michael

 
too quick --- I did not have the chance to help out --- glad u got it
 
Try this:

%let oldvar = 'TECH';
%let newvar = %SYSFUNC(compress(&oldvar, "'"));

%SYSFUNC executes SAS language functions or user-written functions within the macro facility.
 
teralearner - I have wanted to do that for YEARS and SAS support said it was not possible --- have a 'star' on me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top