BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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)

 

Please help

12 REPLIES 12
Reeza
Super User

Is it a number or character?

 

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

Astounding
PROC Star

One possibility:

 

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

 

See if that's what you need.

knveraraju91
Barite | Level 11

Thank you for help.

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

 

 

Reeza
Super User

If you have an answer please mark the question answered 🙂

knveraraju91
Barite | Level 11

 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.

Reeza
Super User

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.) || '%)';
knveraraju91
Barite | Level 11

The variable is zero. Thank you

Astounding
PROC Star

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.

Reeza
Super User

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%)

 

 

knveraraju91
Barite | Level 11

Hi I have another questions.

I need to produce a report like this: File attached 

 

I am using the code: The output doesnot look same. Please help

 

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 "Program: /CA17139/sas_prg/stsas/tab/adam_tblae1a_auto.sas 16DEC2015 12:16";
footnote2 " %sysget(sas_execfilepath) &sysdate. &systime.";
options orientation=landscape formchar="|----|+|---+=|-/\<>*";

ods rtf file="C:\Users\vvemireddy\Desktop\ae_1.rtf" style=journal;
proc report data=four nowd headline headskip style(report)=[frame=void];
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;

 

Reeza
Super User

If this question is answered please mark this one answered and create a new question.

ballardw
Super User

Also without data we have no idea what your resulting report actually looks like.

 

Please describe how it doesn't look right.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 12 replies
  • 1305 views
  • 0 likes
  • 4 in conversation