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

What am I missing in a data step to allow me to use substring to fill the year of a date?

proc sql;
create table test1
(academic_period varchar2(6));
quit;
proc sql;
insert into test1 (academic_period) values ('199910');
quit;
data test1; set test1;
	If SUBSTR(ACADEMIC_PERIOD,5,2) = '10' then somedate = input("10/15%str(SUBSTR(t1.ACADEMIC_PERIOD,1,4)))", mmddyy10.);
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
 input(catt("10/15/", SUBSTR(ACADEMIC_PERIOD,1,4)), mmddyy10.)

Maybe something like that? 

May also be worth looking at MDY() function if you want a SAS date?

 

Edit - remove the t1 reference since that's only good in SQL

 


@DavidPhillips2 wrote:

What am I missing in a data step to allow me to use substring to fill the year of a date?

proc sql;
create table test1
(academic_period varchar2(6));
quit;
proc sql;
insert into test1 (academic_period) values ('199910');
quit;
data test1; set test1;
	If SUBSTR(ACADEMIC_PERIOD,5,2) = '10' then somedate = input("10/15%str(SUBSTR(t1.ACADEMIC_PERIOD,1,4)))", mmddyy10.);
run;

 


 

View solution in original post

5 REPLIES 5
Reeza
Super User
 input(catt("10/15/", SUBSTR(ACADEMIC_PERIOD,1,4)), mmddyy10.)

Maybe something like that? 

May also be worth looking at MDY() function if you want a SAS date?

 

Edit - remove the t1 reference since that's only good in SQL

 


@DavidPhillips2 wrote:

What am I missing in a data step to allow me to use substring to fill the year of a date?

proc sql;
create table test1
(academic_period varchar2(6));
quit;
proc sql;
insert into test1 (academic_period) values ('199910');
quit;
data test1; set test1;
	If SUBSTR(ACADEMIC_PERIOD,5,2) = '10' then somedate = input("10/15%str(SUBSTR(t1.ACADEMIC_PERIOD,1,4)))", mmddyy10.);
run;

 


 

DavidPhillips2
Rhodochrosite | Level 12
proc sql;
create table test1
(academic_period varchar2(6));
quit;
proc sql;
insert into test1 (academic_period) values ('199910');
quit;
data test1; set test1;
	format somedate  mmddyy10.;
	If SUBSTR(ACADEMIC_PERIOD,5,2) = '10' then somedate = mdy(10, 15, SUBSTR(ACADEMIC_PERIOD,1,4));
	
run;

This worked. 

Tom
Super User Tom
Super User

I don't think the MMDDYY informat is going to like a date string that has the letters 'SUBS' in the location where it is expecting the 4 digits of the year.

data test1; set test1;
  If SUBSTR(ACADEMIC_PERIOD,5,2) = '10' then 
    somedate = input(cats('10/15/',SUBSTR(ACADEMIC_PERIOD,1,4),mmddyy10.)
  ;
run;
Tom
Super User Tom
Super User

Why not just use the YYMMN informat?

119   data x;
120     x = input('199910',yymmn6.);
121     put x= date9.;
122   run;

x=01OCT1999
Reeza
Super User
Depending on what you need to scale to, may be better to go to MDY() function using period as month and day as 15 and year from academic period.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 647 views
  • 3 likes
  • 3 in conversation