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.
Not really
You could create a list of all variables that end in date using dictionary.Columns/sashelp.vcolumn but it may not be worth it.
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;
IIf the variables are side by side you can use --
format firstvar--lastvar date9.;
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;
If you put the FORMAT statement after the SET it won't reorder the variables in HAVE.
Good point! I changed it in my post.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.