Hi,
I have a folder with a 30-40 datasets. I have created a macro to look for dates within those datasets but keep getting errors for datasets that don't have dates in them.
How can I create a macro for fields that only have "Date" in the variable name and will check all datasets within a folder?
For example,
data path.dates;
FirstName $ LastName $ StartDate EndDate ;
datalines;
Bill Smith 201902 20190301
Ben Junior 2019 20190131
;
run;
data path.nondates;
FirstName $ LastName$ City $;
datalines;
Linda Davis NY
Sue Smith LA
;
run;
want to add dashes to all fields within the folder that have "Date" in the variable name:
proc sql;
create table path.? as
select *, case when length(strip(Date?)) = 8 then catx("-", substr(strip(Date?), 1,4) ,substr(strip(Date?),5,2),
substr(strip(Date?),7, 2))
when length(strip(Date?)) = 6 then catx("-", substr(Date?, 1,4),substr(Date?,5,2))
else Date?
end as Date? from path.?
;
Quit;
Thanks for your help
Assuming these are SAS datasets use the SASHELP.VCOLUMNS table instead.
libname myFiles 'path to my SAS files';
proc sql;
create table date_vars as
select *
from sashelp.vcolumn
where upcase(libname)='MYFILES' and upcase(name) like '%DATE%';
quit;
@arde wrote:
Hi,
I have a folder with a 30-40 datasets. I have created a macro to look for dates within those datasets but keep getting errors for datasets that don't have dates in them.
How can I create a macro for fields that only have "Date" in the variable name and will check all datasets within a folder?
For example,
data path.dates;
FirstName $ LastName $ StartDate EndDate ;
datalines;
Bill Smith 201902 20190301
Ben Junior 2019 20190131
;
run;
data path.nondates;
FirstName $ LastName$ City $;
datalines;
Linda Davis NY
Sue Smith LA
;
run;
want to add dashes to all fields within the folder that have "Date" in the variable name:
proc sql;
create table path.? as
select *, case when length(strip(Date?)) = 8 then catx("-", substr(strip(Date?), 1,4) ,substr(strip(Date?),5,2),
substr(strip(Date?),7, 2))
when length(strip(Date?)) = 6 then catx("-", substr(Date?, 1,4),substr(Date?,5,2))
else Date?
end as Date? from path.?
;
Quit;
Thanks for your help
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.