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
Super User

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;
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 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
  • 6 replies
  • 796 views
  • 4 likes
  • 5 in conversation