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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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