Is there a SAS created variable like _all_ or _numeric_ for date variables?
I'm automating reports and the following code works but I was wondering if I could get more specific and say "format all date values as" instead of "format all numeric values as"
proc report data=data;
columns _all_;
define _numeric_ /style={TAGATTR='format:m/d/yyyy'};
run;
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
It would like be (untested):
Define date_: / format=..... ;
This assumes all and only date variables start with DATE_.
@sfridy wrote:
What is the colon shortcut and how would it be implemented using proc report?
Nope. Date variables are numbers/numeric.
If you have a naming convention you can use the colon shortcut. Make all your date variables start with a common prefix such as:
Date_:
@sfridy wrote:
Is there a SAS created variable like _all_ or _numeric_ for date variables?
I'm automating reports and the following code works but I was wondering if I could get more specific and say "format all date values as" instead of "format all numeric values as"
proc report data=data; columns _all_; define _numeric_ /style={TAGATTR='format:m/d/yyyy'}; run;
What is the colon shortcut and how would it be implemented using proc report?
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html
It would like be (untested):
Define date_: / format=..... ;
This assumes all and only date variables start with DATE_.
@sfridy wrote:
What is the colon shortcut and how would it be implemented using proc report?
No. Dates are merely formatted integers. SAS doesn't know which numeric variables are interpreted as dates and which are not.
Since "date" variables are inferred based on their assigned SAS formats, you could also create a list of these (regardless of name) by examining the FMTINFO function, "Cat" attribute. Some testing required 😉
%let lib=SASHELP;
%let mem=AIR;
proc sql noprint;
select t1.name into: dateVars separated by ' '
from sashelp.vcolumn t1
where libname="&lib." and memname="&mem"
and fmtinfo(scan(t1.format,1),'Cat')="date"
;
quit;
%put &=dateVars;
proc report data=&lib..&mem.;
columns _all_;
define &datevars. / display style={TAGATTR='format:m/d/yyyy'};
run;
@ChrisHemedinger wrote:
Since "date" variables are inferred based on their assigned SAS formats, you could also create a list of these (regardless of name) by examining the FMTINFO function, "Cat" attribute. Some testing required 😉
%let lib=SASHELP; %let mem=AIR; proc sql noprint; select t1.name into: dateVars separated by ' ' from sashelp.vcolumn t1 where libname="&lib." and memname="&mem" and fmtinfo(scan(t1.format,1),'Cat')="date" ; quit; %put &=dateVars; proc report data=&lib..&mem.; columns _all_; define &datevars. / display style={TAGATTR='format:m/d/yyyy'}; run;
The DEFINE statement is a bit eccentric about the difference between a "SAS Variable List" and a "list of SAS variables".
81 proc report data=&lib..&mem.;
SYMBOLGEN: Macro variable LIB resolves to SASHELP
SYMBOLGEN: Macro variable MEM resolves to class
82 columns _all_;
83 define height weight / display style={TAGATTR='format:m/d/yyyy'};
------
79
ERROR: HEIGHT does not have a numeric suffix.
ERROR 79-322: Expecting a -.
84 run;
My SAS does not have SASHELP.AIR;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.