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

Good day SAS Community,

 

I have a question concerning manipulation of dates in SAS. Suppose I have a numerical variable for year (ex: 2016, 2017, etc...) and I instead wanted to generate a second date (DATE9.) variable that would be set to January 1st, for each of those years (ex: 2016-01-01, 2017-01-01).

 

How would I go about doing this in SAS?

 

idyearnew_date
1201501JAN2015
2201401JAN2014
3200801JAN2008
4199901JAN1999

 

Thank you again for your help,

-Carmine

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

if year is numeric years

 

new_date=mdy(1,1,year);

format new_date date9.;

 


data w;
do year=2015 to 2025;
new_date=mdy(1,1,year);
output;
end;
format new_date date9.;
run;

View solution in original post

3 REPLIES 3
UdayGuntupalli
Quartz | Level 8

@Carmine_Rossi
      You may try this : 

 

data want;
          set have; 
         dt = DatePart(new_date); 
         Year1 = Year(dt); 
          Month1 = Month(dt);
          Day1 = Day(dt); 
          Hour1 = Hour(dt); 
run;
novinosrin
Tourmaline | Level 20

if year is numeric years

 

new_date=mdy(1,1,year);

format new_date date9.;

 


data w;
do year=2015 to 2025;
new_date=mdy(1,1,year);
output;
end;
format new_date date9.;
run;

Carmine_Rossi
Calcite | Level 5

Thank you very much! The MDY function is what I was looking for!

-Carmine

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 396 views
  • 0 likes
  • 3 in conversation