PROC IMPORT DBMS=ACCESSCS DATATABLE='RVDEC'
Hello,
You can use the vformat function to check the formats of the elements in an array.
Also, you cannot change the format of a dataset column on the fly. You have to create a new
column and drop the old one.
data mpart;
format BDAY REcDate ReTDate datetime.;
BDAY=datetime();
RecDate=datetime();
RetDate=datetime();
x=1;
run;
data _NULL_;
set work.mpart;
array fixed _NUMERIC_;
call execute('data want; set work.mpart;');
do over fixed;
if vformat(fixed)=:"DATETIME" then do;
varname=vname(fixed);
call execute(cat('drop ',strip(varname),';'));
call execute(cat('format N_',strip(varname),' date9.;'));
call execute(cats('N_',varname,'=datepart(',varname,');'));
end;
end;
call execute('run;');
stop;
run;
Here is the log when using the do loop method
Please post the log as text as some contributors cannot or won't open attached documents.
It would be useful to have the complete log indicating which code has been executed.
For instance, here is the log i obtain :
696
697 data _NULL_;
698 set work.mpart;
699 array fixed _NUMERIC_;
700
701 call execute('data want; set work.mpart;');
702
703 do over fixed;
704 if vformat(fixed)=:"DATETIME" then do;
705 varname=vname(fixed);
706 call execute(cat('drop ',strip(varname),';'));
707 call execute(cat('format N_',strip(varname),' date9.;'));
708 call execute(cats('N_',varname,'=datepart(',varname,');'));
709 end;
710 end;
711
712 call execute('run;');
713
714 stop;
715 run;
NOTE: There were 1 observations read from the data set WORK.MPART.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: CALL EXECUTE generated line.
1 + data want; set work.mpart;
2 + drop BDAY;
3 + format N_BDAY date9.;
4 + N_BDAY=datepart(BDAY);
5 + drop REcDate;
6 + format N_REcDate date9.;
7 + N_REcDate=datepart(REcDate);
8 + drop ReTDate;
9 + format N_ReTDate date9.;
10 + N_ReTDate=datepart(ReTDate);
11 + run;
NOTE: There were 1 observations read from the data set WORK.MPART.
NOTE: The data set WORK.WANT has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
hi! After running it in Base SAS (as opposed to enterprise guide) I was able to get a successful output!
Thank you so much.
You can use an attrib statement in a data step.
Attrib BDAY REcDate ReTDate Y201 Y22 Y716 Y133 Y876 Y7623 Y8613 Format = Date9.;
I would suggest making your columns wider. I'm guessing that it is displaying that way in your dataset due to the columns not being wide enough.
Since you have datetime variables initially, they have to be converted to date variables for the format to correctly be applied.
Data Want;
Set Have;
Array X _Numeric_;
Do Over X;
X = Datepart(X);
End;
Attrib _Numeric_ Format = Date9.;
/* If you have other numeric variables in your dataset which you do not want to apply the format to, then specify each variable you want the format applied to. */
Run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.