BookmarkSubscribeRSS Feed
crayfordsean
Calcite | Level 5

Hi,

I'd like to know if there is a way of formatting all the date variables using a wildcard naming convention. For instance, if you have 4
date variables (datestart, dateend, datedue and datestopped), you can use the following; 'format date: ddmmyy8.;' but if the

variables were called startdate, enddate, duedate and stopdate, is there a way to wildcard the variable name from the beginning ?

Thanks for any help offered.

6 REPLIES 6
Reeza
Super User

Not really Smiley Sad

You could create a list of all variables that end in date using dictionary.Columns/sashelp.vcolumn but it may not be worth it.

Loko
Barite | Level 11

Hello,

As Reeza stated you may use the dictionary. Something like this:

proc sql noprint;
select name into :vars separated by ' ' from sashelp.vcolumn
where memname='CLASS' and libname='SASHELP' AND name like '%e';
quit;

%put &vars;

data want;
informat &vars $15.; 
set sashelp.class (drop=&vars) ;
run;

Reeza
Super User

IIf the variables are side by side you can use --

format firstvar--lastvar date9.;

art297
Opal | Level 21

If the variables aren't side by side here is a working example of what Fareeza suggested:

data have;

  input startdate x enddate y duedate stopdate;

  cards;

1 2 3 4 5 6

2 3 4 5 6 7

;

proc sql noprint;

  select name into :vars

    separated by ' '

      from sashelp.vcolumn

      where libname='WORK' and

            memname='HAVE' and

            name like '%date'

  ;

quit;

data want;

  set have;

  format &vars. date9.;

run;

data_null__
Jade | Level 19

If you put the FORMAT statement after the SET it won't reorder the variables in HAVE. 

art297
Opal | Level 21

Good point! I changed it in my post.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1469 views
  • 0 likes
  • 5 in conversation