## data step

Super Contributor
Posts: 323

# data step

I need help in my code.

a values =100 and 12

I need to have values like this (100%)

(  12%)

I am using the code       cat("(",right(a),")").

I am getting values (100.0) and ( 12.0)

Super User
Posts: 23,683

## Re: data step

Is it a number or character?

new_var= catt("(", put(old_var/100, percent8.1), ")");

Super User
Posts: 6,754

## Re: data step

One possibility:

newvar = '(' || put(a, 3.) || '%)';

See if that's what you need.

Super Contributor
Posts: 323

## Re: data step

Thank you for help.

This code help me. newvar = '(' || put(a, 3.) || '%)';

Super User
Posts: 23,683

## Re: data step

Super Contributor
Posts: 323

## Re: data step

The code newvar = '(' || put(a, 3.) || '%)'; works for me as long as 'a' values are not zero.

for example when a=17,  I am  getting 17 ( 28%) what i need.

In some observation there are values i need to concatenate zero number also.

for example when a=0,  I need values 0 (  0%). But iam getting  0 ( %). Please help.

Thank you.

Super User
Posts: 23,683

## Re: data step

Is the variable you're using missing in that circumstance or is it 0?

I'm going to guess it's missing. You can use the COALESCE() function to assign the value 0 when the variable is missing.

``newvar = '(' || put(coalesce(a, 0), 3.) || '%)';``
Super Contributor
Posts: 323

## Re: data step

The variable is zero. Thank you

Super User
Posts: 6,754

## Re: data step

Just the fact that you could possibly get 17 ( 28%) means that your program is a little different than what I imagine it to be.  Show us exactly what is in your program (just the one or two relevant lines of code), and what the data values are to generate the wrong result.

Super User
Posts: 23,683

## Re: data step

If it was 0, it should work. Make sure you have no formats applied to the data that's causing 0 to appear as missing.

``````data have;
x=0;
y="("||put(x, 3.)||"%)";
run;
proc print; run;

``````

Output:

``````
Obs	x	y
1	0	( 0%)``````

Super Contributor
Posts: 323

## Re: data step

Hi I have another questions.

I need to produce a report like this: File attached

OPTIONS nodate nonumber;
ods listing close;
ods escapechar="^";
title1 justify=right 'page ^{pageof}';
title2 "Table 14.3.1.1 Treatment-Emergent Adverse Event Frequency by Treatment -";

title3 "Number of Subjects Reporting the Event (% of Subjects Dosed) (Safety Population)";
footnote1 "Note: Adverse events (AEs) were coded with MedDRA Version 18.0.";
footnote2 " %sysget(sas_execfilepath) &sysdate. &systime.";
options orientation=landscape formchar="|----|+|---+=|-/\<>*";

ods rtf file="C:\Users\vvemireddy\Desktop\ae_1.rtf" style=journal;
column grp aebodsys aedecod aetext cnt_pct4 ("JPZ" "_______________" cnt_pct1 cnt_pct2) cnt_pct3 cnt_pct5;
define grp/order noprint;
define aebodsys/order noprint;
define aedecod/display center noprint;
define aetext/ display 'Adverse Event' style(column)={asis=on cellspacing=.25pt just=left};
define cnt_pct1 / "300 mg" style(column)={cellspacing=.25pt just=left};
define cnt_pct2/ "900 mg" style(column)={cellspacing=.25pt just=left} ;
define cnt_pct3/ "400 mg Moxifloxacin" style(column)={cellspacing=.25pt just=left};
define cnt_pct4/"Plcebo" style(column)={cellspacing=.25pt just=left} ;
define cnt_pct5/"TOTAL" style(column)={cellspacing=.25pt just=left} ;
compute after grp/style={protectspecialchars=off};
n+1;
len=ifn(n=1,20,0);
dummy='\brdrt\brdrs';
line dummy \$varying20. len;
endcomp;
run;
ods rtf close;

Super User
Posts: 23,683

Super User
Posts: 13,508