BookmarkSubscribeRSS Feed
shivamarrora0
Obsidian | Level 7

Hi everyone,

 

I want to assign different format according to the value of the var

 

suppose if the value of variable is a,b,c then all the numeric variable show percent format

other show normal number format.

 

2 REPLIES 2
kiranv_
Rhodochrosite | Level 12

you can use call define statement in proc report

 

 

data have;
input id $ val;
datalines;
a .1
b .5
c .7
d 5
;




proc report nowd data=have;
   col id val; 
   compute val;
      if id in('a','b', 'c') then do;
         call define(_col_,'format','percent10.2');
      end;
   endcomp;
run;

 

Cynthia_sas
SAS Super FREQ

Hi:

  You can do this in a PROC REPORT COMPUTE block. There have been many previous postings on this topic. Here's an example of the COMPUTE block if you wanted to change the format for the whole row:

compute var_b;
   if var_a in ('a', 'b', 'c') then do;
      call define(_row_,'format','percent9.2');
   end;
   else if var_a in ('d','e') then do;
      call define(_row_,'format','comma6.');
   end;
endcomp;

  If you only wanted selected columns/variables to be formatted, then the CALL DEFINE would change to:

call define('thevar','format','comma6.');

 

  Anything other than _col_ or _row_ must be quoted as the first argument in the CALL DEFINE.

 

Hope this helps,

 

cynthia

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
  • 2 replies
  • 596 views
  • 0 likes
  • 3 in conversation