Help using Base SAS procedures

Macro variable in PROC FORMAT

Reply
Contributor
Posts: 57

Macro variable in PROC FORMAT

Hi,

proc sql noprint;
select distinct(aN) into :dA1-:dA2
from dasd
group by step;
quit;

proc format;
value $tafmt 'X' = 'X (n="&dA1")'
'D' = 'D (n="&dA2")';
run;

If I attach this format to the value, I'm getting X(n=&denomA1) . The macro variable is not resolving. I even tried giving everything in double quotes in PROC FORMAT.

Thanks in Advance,
Sandy.
Valued Guide
Posts: 2,175

Re: Macro variable in PROC FORMAT

reverse those quotes
&macro_vars resolve inside doubles, but not single quotes (, at the outer level). So try
value $tafmt 'X' = "X (n='&dA1')"
'D' = "D (n='&dA2')";
run;

However, this resolves the macro variables when proc format executes. Was that what you wanted?

PeterC
Super Contributor
Super Contributor
Posts: 3,174

Re: Macro variable in PROC FORMAT

I agree with Peter.C -- best to explain how you intend to use this narrow focus example with PROC SQL to generate suitable data values for a PROC FORMAT code execution?

Also, from my testing with the OP's code, either technique for coding the single or double quote yields the same format contents, so if you are getting "denom" there is some other problem with your code.

Suggest you use the SAS command below to see what SAS macro variables have as values:

%PUT _ALL_;

..or..

%PUT _GLOBAL_;

..or..

%PUT _LOCAL_;


Also, suggest you use the FMTLIB parameter with PROC FORMAT to see what's being generated as output to your format.

Scott Barry
SBBWorks, Inc.
Trusted Advisor
Posts: 1,131

Re: Macro variable in PROC FORMAT

Hi Sandya,

i mimicked your code using the sashelp.class dataset like below

proc sql;

select name into :name1-:name19 from sashelp.class;

quit;

The above code will create the macro variables like name1,name2....; inorder to check if the macro variable is getting resolved in the format i created i used the fmtlib option, i found that it is not resolving and the reason for this is the syntax in the proc format value

    proc format fmtlib;

      value $tafmt 'X' = 'X (n="&name1")';

    run;

the correct syntax would be as below

proc format fmtlib;

     value $tafmt 'x'="x(n=&name1)";

run;

make sure that you put only once opening and closing quote for the label as "x(n=&name1)";. Hope this will be helpful.

Thanks,

Jagadish

Thanks,
Jag
Ask a Question
Discussion stats
  • 3 replies
  • 506 views
  • 0 likes
  • 4 in conversation