BookmarkSubscribeRSS Feed
garag
Calcite | Level 5

Hi,

I was trying to run the following put in a data step

data b;

  length formattoapply $20;

input formattoapply $;

cards;

YYMMN4.

date9.

datetime20.

;

run;

data a;

  set b;

  newdate = put (today(), formattoapply);

run;

where formattoapply is a column of b that should contains differents formats for differents rows.

If I run this, I get ERROR 85-322: Expecting a format name.

Do there is a way to apply a different format for different rows where the format to apply is contained in a column?

many thanks.

regards

7 REPLIES 7
data_null__
Jade | Level 19

that would the putN function in this case.

UrvishShah
Fluorite | Level 6

Based on my knowledge, it is not possible to apply multiple format to different rows for variable...You can read the variable containing different dates structure as charcter variable and can fix it as charcter variable...

However, it will be good if you can share the purpose of your analysis by using this date variable in subsequent step...

Usually, variable types creates conflict in appending and joining (merging) SAS Datasets...

If your aim is structurize the same dates for all the rows then need to think out of box!!!

-Urvish

Cynthia_sas
SAS Super FREQ

HI:

  In a report (as opposed to a table), you can apply different formats to data cells on a report row using PROC REPORT and CALL DEFINE.

Cynthia

ods html file='c:\temp\diff_fmt.html';

proc report data=sashelp.class nowd;
  column name age sex ;
  define name / order;
  define age / display f=6.0;
  define sex / display;
  compute age;
    if name in ('Alfred', 'Alice', 'James') then do;
      call define(_col_,'format','9.3');
      call define(_col_,'style','style={background=yellow}');
    end;
  endcomp;
run;
ods html close;

robertrao
Quartz | Level 8

Hi Cynthia,

i have a couple of questions?

Is call define used only in the compute block ????

it can eithwer be _col_ or _row_ in the call define..........cannot be both at the same time right?

Thanks

data_null__
Jade | Level 19

Maybe you could take Cynthia's example and experiment.  Add a call define(_row_ and see what happens. 

Cynthia_sas
SAS Super FREQ

Hi:

There are some situations (such as changing background color) that are appropriate for a _row_; however, it would not be appropriate to use _row_ for a format, when the report row contains both character and numeric variables...a numeric format cannot be used with a character variable.

  The doc on CALL DEFINE is quite clear that you can have something other than _col_ or _row_, you can used a named variable, an absolute column number, and even an expression that resolves to a variable name. A CALL DEFINE statement can only be used in a COMPUTE block and only with PROC REPORT (not PRINT, not TABULATE).

cynthia

Vish33
Lapis Lazuli | Level 10

Hi,

We can apply multiple formats for a single variable as required. I faced this in my previous project to create multiple formats for each row.

You can see the attachment which i have created with multiple formats using Proc Report and call define as Cynthia said.

Thanks,

VishnuDifferent_formats_on_variable.jpg

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 3096 views
  • 3 likes
  • 6 in conversation