BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am using the following code to create new variables but am having trouble creating the label/column header.

This is a monthly table - each month a new column is appended with that month's data. I am capturing the variable names and labels in macro variables and then using these to create new variables. The label name is a number, signifying the year and month ie this month's column is 200903. When I try to put the macro variable with this value as a column header, I get an error. Code as below.

proc contents data=reports.times_&yyyymm. out=work.contents noprint;
run;

data _null_;
set WORK.contents (where=(name ne "metric"));
call symput('var'||compress(_N_),compress(name));
call symput('label'||compress(_N_),compress(label));
call symput('n',compress(_N_));
run;


proc report data = reports.times_&yyyymm. NOWINDOWS NOCENTER MISSING
style(column)={font_size=10pt}
style(header)={font_size=10pt};
title;
title1 "Report 21";
footnote;
column metric _:;
%do i=1 %to &n;
column var&i;
define metric/display;
define &&var&i/display noprint;
define var&i/computed;
compute var&i/CHARACTER length=30 "&&label&i";
if index(metric,'LGD')>0
or index(metric,'PD')>0
or metric='Sum EL / Sum Pre-Severity EL' then var&i=put(&&var&i,&formb);
else var&i=put(&&var&i,&forma);
endcomp;
%end;
run;

Thanks in advance.
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi:
The label string goes on the DEFINE statement for the variable, NOT on the COMPUTE statement.

cynthia
deleted_user
Not applicable
Thanks Cynthia

You are awesome!

Drew

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 2 replies
  • 1704 views
  • 0 likes
  • 2 in conversation