I am interested in using the value of an ACROSS variable in the URL of my Call Define statement in my compute statement.
In the example below, I'm wondering if Proc Report gives me a way to access the value of each TYPES variable as the columns are being built, so that I can include it in the URL link? Can I access the value from a compute statement using the N variable?
Thanks for the help.
options missing="";
data REPORT;
input VARIABLE $ TYPES $;
datalines;
VAR1 TYPE1
VAR1 TYPE2
VAR1 TYPE3
VAR1 TYPE5
;
PROC FORMAT ;
VALUE $TYPE
'TYPE1'='Type 1'
'TYPE2'='Type 2'
'TYPE3'='Type 3'
'TYPE4'='Type 4'
'TYPE5'='Type 5';
Run ;
proc report data=REPORT nowd;
column ("Variables" variable) ("TYPES" types,n);
define variable / '';
define types / across '' format=$type. preloadfmt;
define n / '' format=comma12.;
compute types;
If _c2_>0 then
call define("_c2_","style","style={url = '<MY URL>' }");
endcomp;
run;
Alternately, if you're trying to get the "Type 2" etc. into the name, I think you would go this route (using a format, and _COL_ instead of "_C2_"). I don't think there's a way to directly access the across value itself.
Since you're presumably constructing these compute blocks individually through use of a macro, I probably would eschew the format and just pass the value of the variable to the macro directly if you can. If not, then the format may be useful.
PROC FORMAT ;
VALUE $TYPE
'TYPE1'='Type 1'
'TYPE2'='Type 2'
'TYPE3'='Type 3'
'TYPE4'='Type 4'
'TYPE5'='Type 5';
value NType
1='Type 1'
2='Type 2'
3='Type 3'
4='Type 4'
5='Type 5';
Run ;
proc report data=REPORT nowd;
column ("Variables" variable) ("TYPES" types,n);
define variable / '';
define types / across '' format=$type. preloadfmt;
define n / '' format=comma12.;
compute types;
If _c2_>0 then
call define(_COL_,"style",cats("style={url = '",put(_COL_,NType.),"'" ));
endcomp;
run;
Do you mean like this?
proc report data=REPORT nowd;
column ("Variables" variable) ("TYPES" types,n);
define variable / '';
define types / across '' format=$type. preloadfmt;
define n / '' format=comma12.;
compute types;
If _c2_>0 then
call define("_c2_","style",cats("style={url = '",_C2_,"'" ));
endcomp;
run;
Alternately, if you're trying to get the "Type 2" etc. into the name, I think you would go this route (using a format, and _COL_ instead of "_C2_"). I don't think there's a way to directly access the across value itself.
Since you're presumably constructing these compute blocks individually through use of a macro, I probably would eschew the format and just pass the value of the variable to the macro directly if you can. If not, then the format may be useful.
PROC FORMAT ;
VALUE $TYPE
'TYPE1'='Type 1'
'TYPE2'='Type 2'
'TYPE3'='Type 3'
'TYPE4'='Type 4'
'TYPE5'='Type 5';
value NType
1='Type 1'
2='Type 2'
3='Type 3'
4='Type 4'
5='Type 5';
Run ;
proc report data=REPORT nowd;
column ("Variables" variable) ("TYPES" types,n);
define variable / '';
define types / across '' format=$type. preloadfmt;
define n / '' format=comma12.;
compute types;
If _c2_>0 then
call define(_COL_,"style",cats("style={url = '",put(_COL_,NType.),"'" ));
endcomp;
run;
No, your other answer is, I think, the closest I can get to a solution. I am now convinced that the across variable's value is not available from Proc Report.
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!
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.