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
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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