My "period" variable is a character variable which has the format $32. It can take on the following values:
2004-2007
[...]
2013-2016
2015-2016,2018
2018, 2020
2018,2020,2021
2020,2021,2022
I use the compute block in PROC REPORT in order to use these periods as headlines for the values in that time period:
ods excel file="[path]";
ods excel options(sheet_interval='bygroup' sheet_name="#byval(bladnamn)");
PROC REPORT data=export;
by bladnamn;
column period variabelnamn bladnamn variabel_cat_varde (kon,(andel CI_lower CI_upper lillan));
/* define variabelnamn / order order=internal;*/
define period / group order=internal descending format=$32. noprint;
define variabelnamn / group order=data noprint;
define order / order order=internal noprint;
define variabel / order order=internal noprint;
define bladnamn / group order=data noprint;
define variabel_cat_varde / order=data group;
/*define alder_grupp / order=data group;*/
define andel / mean;
define CI_lower / mean;
define CI_upper / mean;
define lillan / mean;
DEFINE kon / ACROSS ORDER=INTERNAL;
compute before period /style={just=left};;
period_char= put(period, $32.);
line period_char $char200.;
endcomp;
compute before variabelnamn /style={just=left};;
line variabelnamn $char200.;
endcomp;
run;
ods excel close;
The "period" values separated by commas are however converted to scientific notation in the COMPUTE block, despite my best efforts:
This is however just an issue with the comma-separated values. More specifically, this only seems to happen with the entries with three comma-separated values.
Can I keep this from happening and in that case how?
data have;
input period :$40. a $ x;
cards;
2018,2020,2021 a1 12
2018,2020,2021 a2 1
2020,2021,2022 b1 6
2020,2021,2022 b2 7
;
ods excel file='c:\temp\temp.xlsx';
proc report data=have nowd;
column period a x;
define period/group noprint;
define a/display;
define x/display;
compute before period /style={just=left tagattr='type:string'};
line period $char200.;
endcomp;
run;
ods excel close;
data have;
input period :$40. a $ x;
cards;
2018,2020,2021 a1 12
2018,2020,2021 a2 1
2020,2021,2022 b1 6
2020,2021,2022 b2 7
;
ods excel file='c:\temp\temp.xlsx';
proc report data=have nowd;
column period a x;
define period/group noprint;
define a/display;
define x/display;
compute before period /style={just=left tagattr='type:string'};
line period $char200.;
endcomp;
run;
ods excel close;
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.