BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Syntas_error
Quartz | Level 8

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:

 

Syntas_error_0-1689929107738.png

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

Ksharp_0-1689940074264.png

 

View solution in original post

2 REPLIES 2
Ksharp
Super User
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;

Ksharp_0-1689940074264.png

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 370 views
  • 1 like
  • 2 in conversation