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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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