If you have a dataset with a bunch of datetime fields (that you brought in from an external database, for example) and you want to work with them date9, this will generate a view of that dataset for you.
%macro date9(lib,dsn); /* this macro will create a view with datepart function applied to all datetime fields */ data vars; length name $ 50 type $ 1 format informat $ 50 label $ 50; drop dsid i num rc; dsid=open("&lib..&dsn","i"); num=attrn(dsid,"nvars"); do i=1 to num; name=varname(dsid,i); type=vartype(dsid,i); format=varfmt(dsid,i); informat=varinfmt(dsid,i); label=varlabel(dsid,i); length=varlen(dsid,i); position=varnum(dsid,name); output; end; rc=close(dsid); run; proc sql; select case when format contains 'DATETIME' then 'datepart('||trim(name)||') as '||trim(name)||' format=date9.' else name end as name into :names1- from vars; %let recs=&sqlobs; proc sql; create view &lib..vw_&dsn as select &names1 %do i=2 %to &recs; , &&names&i %end; from &lib..&dsn ; %mend;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.