BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
saraphdnz
Quartz | Level 8

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;

 

Capture.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

5 REPLIES 5
Reeza
Super User

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;

 

Capture.JPG




saraphdnz
Quartz | Level 8

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;

Capture.JPG

 

Patrick
Opal | Level 21

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;
saraphdnz
Quartz | Level 8

Thanks Patrick for your help, it is now giving me the results. Regards, Sara 

ballardw
Super User

run Proc Contents on Myfiles.Dset1 and show us all of the properties for your current Date variable.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 789 views
  • 4 likes
  • 4 in conversation