1
votes

I want to create a table using a data step in SAS that contains the display format codes for SSRS.

For example, I have some codes like this '#,0;(#,0)' but I am getting errors when I try to assign this value in a data step. I also tried to put it in a macro first but it doesn't help.

Code:

%let fmt1 = %STR(#,0;(#,0)); *thousand-comma separator;

data FORMAT_XREF;   
    length METRIC_TYPE DSP_FORMAT $ 20;

    if  METRIC_TYPE = 'TOT_ACCT' then
            do;
                DSP_FORMAT = quote(&fmt1.);
            end;
run;

Error: 34 #,0;(#,0) _ _ 386 180 _ 76 ERROR 386-185: Expecting an arithmetic expression.

ERROR 180-322: Statement is not valid or it is used out of proper order.

ERROR 76-322: Syntax error, statement will be ignored.

1
Arbitrarily adding macro to a program working or not is usually not a good idea. - data _null_
I updated my post. - Airbum88
@Airbum88 Thanks for the update. - Joe

1 Answers

0
votes

Your issue here is that you think the quote function does something different than it does.

The quote function adds double quote characters to something, not the quotations that will serve to delimit a character value. It still takes a character value as input, which you're not providing it (a macro variable contains text, not character values, remember).

So you need:

%let fmt1 = %STR(#,0;(#,0)); *thousand-comma separator;

data FORMAT_XREF;   
    length METRIC_TYPE DSP_FORMAT $ 20;

    if  METRIC_TYPE = 'TOT_ACCT' then
            do;
                DSP_FORMAT = "&fmt1.";
            end;
run;

That should work fine for you. If you actually need quotes in the value also, you can wrap the quote function around that (so DSP_FORMAT = quote("&fmt1."); will store "#,0;(#,0)" in the variable, including the " characters).