How to compute macro variable in proc report, the &varlist. is displaying all column names as one. how to call only one column name.
proc sq;
select name into :varlist from the dictionary.columns where memname='test';
proc report data=qtrresults
column ID test1 test2 &varlist. ;
define ID / display "ID";
define test1 /display "test1";
define &varlist. /display;
compute &varlist.;
if flag:_&varlist. =2 then
call define('dummy3',"style", "style=[font_style=italic background=yellow]");
end;
end comp;
Fix the PROC SQL query so that there's a space between the items. There are many examples on here on how to do that, or the documentation has examples.
@radha009 wrote:
How to compute macro variable in proc report, the &varlist. is displaying all column names as one. how to call only one column name.
proc sq;
select name into :varlist from the dictionary.columns where memname='test';
proc report data=qtrresults
column ID test1 test2 &varlist. ;
define ID / display "ID";
define test1 /display "test1";
define &varlist. /display;
compute &varlist.;
if flag:_&varlist. =2 then
call define('dummy3',"style", "style=[font_style=italic background=yellow]");
end;
end comp;
Why are you putting a list of variables into your macrovar, when you only need the name of one?
@radha009 wrote:
How to compute macro variable in proc report, the &varlist. is displaying all column names as one. how to call only one column name.
This is really impossible to say given the little information you have provided us. "Is displaying all column names as one"??? makes no sense, since you don't tell us what is displaying ... show us what you mean, show us the SASLOG or other indication of the problem.
Further, you need to make sure your SAS syntax is correct.
There is no "proc sq;"
The word "the" does not belong in "select name into :varlist from the dictionary.columns where memname='test';"
and so on
sorry for the typos and the wording.
I want to create a report to show the cells colored if the data doesn't match.
my data few variables are dynamic,every month it will be different but they have a number start with chg so i am putting all columns which starts with %chg%.
------------------------
data comp.check5;
merge descope.load2sp_ds (in=ina) comp.check4;
by Name CI_ID;
if ina;
run;
proc sql noprint;
select name into :varlist separated by ' '
from dictionary.columns
where
libname = "COMP" and
memname = "CHECK1" and
name like '%CHG%';
quit;
proc report data=comp.check5 nowd;
column Name ID test1 test2 flag_: Impacted_Flag Validation_required Validation_status Validator_Name flag_:&varlist. Maint_Window;
define Name / display style(column)=[just=left cellwidth=3.1in]'Name';
define CI_ID / display style(column)=[just=left cellwidth=1.1in] 'ID';
define flag_: / noprint display;
define Impacted_Flag / display style(column)=[just=center cellwidth=1.1in] 'Impacted';
define var / computed display style(column)=[just=center cellwidth=1.1in];
compute Impacted_Flag;
if FLAG_Impacted_flag = 2 then
call define(_col_, "style", "style=[background=yellow]");
endcomp;
compute var;
do i = 1 to dim(var) ;
if FLAG_:&varlist. = 2 then
call define(_col_, "style", "style=[background=yellow]");
end;
endcomp;
One thing you will have to do is loop over all the variable names in &varlist; this loop probably needs to be inside PROC REPORT.
You can't use a list of variable names in PROC Report the way you are doing it.
Change your data structure and use a variable with an ACROSS instead. Then you don't need a lot of this...possibly any.
sorry for the typos and the wording.
I want to create a report to show the cells colored if the data doesn't match.
my data few variables are dynamic,every month it will be different but they have a number start with chg so i am putting all columns which starts with %chg%.
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.
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.