BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello,

raw_tbl contain the following columns:

ID (label: Customer ID)

X (label: Indicator good/bad credit card user)

w (label: Indicator good/bad loans taker)

I want to create a summary table and add a column called label_of_Var that will get the value of label of Var X?

What is the way to do it please?

In this example I wrote it manually "Indicator good/bad credit card user" as label_of_Var

But my question is how to create a code that put automatically label of X as a value of column label_of_Var?

proc sql;
Create table wanted_x as
select  "Ind_X" as Var,
            "Indicator good/bad credit card user" as label_of_Var,
           case when Ind_X=1 then 'Fail' else 'Pass' end as Ind_pass_Fail,
          count(*) as nr,
         calculated nr/(select count(*) from raw_tbl) as pct
From  raw_tbl
group by calculated Ind_pass_Fail;
quit;
3 REPLIES 3
ballardw
Super User

The functions that would allow this are not supported in Proc SQL.

 

 

So you may try

1) Select the label from the Dictionary.columns for the variable X for that source data set and join it to this table

2) Select the label from the dictionary.columns into a macro variable and use that as the value

andreas_lds
Jade | Level 19

Unfortunately the function vlabel is only available in a data step, not in proc sql.

Kurt_Bremser
Super User

Use macro variables:

%let varname=Ind_X;

proc sql noprint;
select label into :varlabel
from dictionary.columns
where libname = "WORK" and memname = "RAW_TBL" and upcase(name) = upcase("&varname.")
;
create table wanted_x as
  select
    "&varname." as Var,
    "&varlabel." as label_of_Var,
    case when Ind_X=1 then 'Fail' else 'Pass' end as Ind_pass_Fail,
    count(*) as nr,
    calculated nr/(select count(*) from raw_tbl) as pct
  from raw_tbl
  group by calculated Ind_pass_Fail
;
quit;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 944 views
  • 0 likes
  • 4 in conversation