Help using Base SAS procedures

variable for all date variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

variable for all date variables

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;

 


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 23,771

Re: variable for all date variables

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


All Replies
Super User
Posts: 23,771

Re: variable for all date variables

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;

 


 

Occasional Contributor
Posts: 10

Re: variable for all date variables

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

Solution
2 weeks ago
Super User
Posts: 23,771

Re: variable for all date variables

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?


 

PROC Star
Posts: 1,283

Re: variable for all date variables

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

Community Manager
Posts: 3,440

Re: variable for all date variables

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 Smiley Wink

 

%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;
Respected Advisor
Posts: 3,852

Re: variable for all date variables

Posted in reply to ChrisHemedinger

@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 Smiley Wink

 

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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