BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Noob
Fluorite | Level 6

Hello,

 

Is it possible to compute/create a character variable in proc report? What I would like to do is take 2 numbers, a create a new character variable that puts them in a from that looks something like this: (18.2, 21.1). However, it seems that maybe compute blocks can only create numeric variables. Is there a way around this?

 

Thanks!

 

proc surveyfreq data=d1;

tables walk / row cl nowt nostd;

stratum final_stratum;

cluster final_cluster;

weight final_weight;

ods output oneway=out_table;

run;

 

proc report data=out_table;

columns table percent lowerCL UpperCL CL;

define table / display;

define percent / display;

define lowerCL / display;

define UpperCL / display;

define CL / computed ;

compute CL; CL = cats("(", LowerCL, ",", UpperCL, ")"); ENDCOMP;

run;

 

Error message:

 

NOTE: Character values have been converted to numeric values at the places given by:

(Line):(Column).

1:7

NOTE: Invalid numeric data, '(78.900921457,81.793697714)' , at line 1 column 7.

NOTE: Invalid numeric data, '(18.206302286,21.099078543)' , at line 1 column 7.

NOTE: Invalid numeric data, '(_,_)' , at line 1 column 7.

NOTE: There were 3 observations read from the data set WORK.out_table.

NOTE: At least one W.D format was too small for the number to be printed. The decimal may be

shifted by the "BEST" format.

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
Hi,
Yes, you can calculate a character variable in a COMPUTE block, but you have to tell the COMPUTE block that it is character. The default is numeric. So instead of this:
compute CL;
CL = cats("(", LowerCL, ",", UpperCL, ")");
ENDCOMP;

use this:
compute CL / character length=20;
CL = cats("(", LowerCL, ",", UpperCL, ")");
ENDCOMP;

cynthia

View solution in original post

3 REPLIES 3
ballardw
Super User

Since you are not actually calculating the values for the limits in the proc report I would think the easier way would be in an intermediate datastep;

data out_table;
   set out_table;
   CL = cats("(", LowerCL, ",", UpperCL, ")"); 
run;

before the Proc report.

 

I would probably use a Put(lowercl,best6.) or similar in the cats function unless you really think the additional digits are helpful.

 

I know of a method that involves custom format to supply leading (, leading comma with trailing ) , style justifications of right and left for adjacent columns, reducing the cellpadding and border widths to 0 to get that appearance in calculated columns

Cynthia_sas
SAS Super FREQ
Hi,
Yes, you can calculate a character variable in a COMPUTE block, but you have to tell the COMPUTE block that it is character. The default is numeric. So instead of this:
compute CL;
CL = cats("(", LowerCL, ",", UpperCL, ")");
ENDCOMP;

use this:
compute CL / character length=20;
CL = cats("(", LowerCL, ",", UpperCL, ")");
ENDCOMP;

cynthia
Noob
Fluorite | Level 6

Thank you both for your helpful replies!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4763 views
  • 2 likes
  • 3 in conversation