Home > Software design >  Macro variable is not printing the table value but instead the column name
Macro variable is not printing the table value but instead the column name

Time:09-14

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.

CodePudding user response:

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;
  • Related