BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sfridy
Fluorite | Level 6

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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?


 

View solution in original post

6 REPLIES 6
Reeza
Super User

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;

 


 

sfridy
Fluorite | Level 6

What is the colon shortcut and how would it be implemented using proc report?

Reeza
Super User

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?


 

PeterClemmensen
Tourmaline | Level 20

No. Dates are merely formatted integers. SAS doesn't know which numeric variables are interpreted as dates and which are not.

ChrisHemedinger
Community Manager

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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
data_null__
Jade | Level 19

@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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1678 views
  • 4 likes
  • 5 in conversation