Search code examples
sqlsasenterprise-guide

Macro variable is not printing the table value but instead the column name


I want to assign these table values to macro variables:

Table values

This is how I assign the table value to the macro variable:

PROC SQL;
   CREATE TABLE Format_YYYYMM_tbl AS 
   SELECT t1.str_perdag_SAS_default FORMAT=YYMMN6. AS Format_YYYYMM,
          ("'"!!put(t1.str_perdag_SAS_default, YYMMN6.)!!"'") AS Format_YYYYMM_quo
      FROM DATOSTAMP t1;
QUIT;

PROC SQL NOPRINT;
SELECT DISTINCT 
          Format_YYYYMM,
          Format_YYYYMM_quo
          
INTO      :Format_YYYYMM,
          :Format_YYYYMM_quo
 
FROM Format_YYYYMM_tbl;

QUIT;

The issue is when I print the values in the log i get the following and not the value in the table:

49         %put Format_YYYYMM_quo;
Format_YYYYMM_quo
50         %put Format_YYYYMM;
Format_YYYYMM 

What am I doing wrong? I hope you can point me in the right direction.


Solution

  • Your %PUT statement is NOT trying to show the value of the macro variables. To reference the value of a macro variable use & before the name of the macro variable.

    %put &Format_YYYYMM_quo;
    

    In the %PUT statement only you can use a special syntax that will print both the name and the value separated by an =.

    %put &=Format_YYYYMM &=Format_YYYYMM_quo;