Hi there,
I am trying to convert my date format into SAS date format so that I can run regression. but somehow I am getting blank date_sas column.
data Myfiles.Dset1;
length date $32;
input date &;
;
Data Myfiles.Bset2;
set Myfiles.Dset1;
if length(date) > 9 then do;
date_part1 = scan(date, 1);
date_sas = input(date_part1, monyy7.);
end;
format date_sas monyy7.;
run;
proc print; run;
Could it be that your date column is already numeric containing a SAS Date value and it's just the format applied that confuses you?
Try below code. What happens? Any errors? How does variable Date print?
Data Myfiles.Dset2;
set Myfiles.Dset1;
format date date9.;
run;
proc print;
run;
The length of all date variable shown there are 7 (3 characters for the month + 4 for the year) so your IF condition would never evaluate to true. I'm not sure why you have an IF condition there at all based on the post. Otherwise, try removing the IF condition and SCAN() and see what you get. But DatePart1 has values so I'm very confused now.
date_sas = input(date, monyy7.);
@saraphdnz wrote:
Hi there,
I am trying to convert my date format into SAS date format so that I can run regression. but somehow I am getting blank date_sas column.
data Myfiles.Dset1; length date $32; input date &; ; Data Myfiles.Bset2; set Myfiles.Dset1; if length(date) > 9 then do; date_part1 = scan(date, 1); date_sas = input(date_part1, monyy7.); end; format date_sas monyy7.; run; proc print; run;
Hello Reeza,
I am still getting a blank column for Date-sas column.
Data Myfiles.Dset2;
set Myfiles.Dset1;
date_sas = input(date, monyy7.);
format date_sas monyy7.;
run;
proc print; run;
Could it be that your date column is already numeric containing a SAS Date value and it's just the format applied that confuses you?
Try below code. What happens? Any errors? How does variable Date print?
Data Myfiles.Dset2;
set Myfiles.Dset1;
format date date9.;
run;
proc print;
run;
Thanks Patrick for your help, it is now giving me the results. Regards, Sara
run Proc Contents on Myfiles.Dset1 and show us all of the properties for your current Date variable.
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.