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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1203 views
  • 0 likes
  • 2 in conversation