BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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