Help using Base SAS procedures

problem interpreting %str syntax

Reply
Contributor
Posts: 32

problem interpreting %str syntax

I saw this in a piece of code - %let custsegs = %str('E|002878','E|010208','00002878','E|X02964','E|002964','CS|E|002878','CS|E|010208','OPT_FA|00002878','CS|E|X02964','CS|E|002964');

Can someone tell me what it means?

Thanks,

DanD
SAS Super FREQ
Posts: 8,744

Re: problem interpreting %str syntax

Hi:
%STR is one of the SAS Macro Facility quoting functions. The relevant sections of the documentation are here:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/tw3514-overvwqt.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001061325.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001072333.htm
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001061345.htm

What will be informative, beyond the doc, is for you to find out WHERE in your code the macro variable &CUSTSEGS is used. For example, if you search for the macro variable in your code, you might find something like this:
[pre]
if WOMBAT in (&custsegs) then do;
... more code ...
[/pre]

which would tell you that the macro variable &CUSTSEGS is used in the IF statement to supply values for the IN operator that is testing the value of the dataset variable WOMBAT. If you then did a PROC FREQ:
[pre]
proc freq data=lib.dataset;
tables WOMBAT;
run;
[/pre]

you would find out whether the values of the WOMBAT variable were correctly specified in the %LET statement inside the %STR function.

Generally speaking any of the Macro Quoting Functions, including %STR are used to mask or hide the normal syntactic meaning of certain special characters, as defined in the documentation. In this instance, I suspect that %STR was used in the %LET statement because someone felt that the single quotes or the pipe symbols needed to be "protected".

cynthia
Contributor
Posts: 32

Re: problem interpreting %str syntax

The variable isn't used anywhere in the code that I have. I only have part of the code.

Thanks for your reply.

DanD
Ask a Question
Discussion stats
  • 2 replies
  • 267 views
  • 0 likes
  • 2 in conversation