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
that would the putN function in this case.
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
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;
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
Maybe you could take Cynthia's example and experiment. Add a call define(_row_ and see what happens.
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
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,
Vishnu
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.