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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.