DATA Step, Macro, Functions and more

data step

Reply
Super Contributor
Posts: 272

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)

 

Please help

Super User
Posts: 19,861

Re: data step

Posted in reply to knveraraju91

Is it a number or character?

 

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

Super User
Posts: 5,516

Re: data step

Posted in reply to knveraraju91

One possibility:

 

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

 

See if that's what you need.

Super Contributor
Posts: 272

Re: data step

Posted in reply to Astounding

Thank you for help.

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

 

 

Super User
Posts: 19,861

Re: data step

Posted in reply to knveraraju91

If you have an answer please mark the question answered Smiley Happy

Super Contributor
Posts: 272

Re: data step

Posted in reply to knveraraju91

 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: 19,861

Re: data step

Posted in reply to knveraraju91

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: 272

Re: data step

The variable is zero. Thank you

Super User
Posts: 5,516

Re: data step

Posted in reply to knveraraju91

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: 19,861

Re: data step

Posted in reply to knveraraju91

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: 272

Re: data step

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;

 

Super User
Posts: 19,861

Re: data step

Posted in reply to knveraraju91

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

Super User
Posts: 11,343

Re: data step

Posted in reply to knveraraju91

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

 

Please describe how it doesn't look right.

Ask a Question
Discussion stats
  • 12 replies
  • 377 views
  • 0 likes
  • 4 in conversation