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

Hello, 

I have years appear as 1990, 1991, 1992 and I need them to appear as 19900101, 19910101, 19920101

How would you go about doing this conversion?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
If your variable is a date, you would change the format. If it's just a number, use MDY() to create a SAS date and then apply the correct format. The format you want is YYMMDDN8.

format dateVar yymmddn8.;

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=leforinforref&docsetTarge...

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Please use MDY function and assign 1 for date and month-

 


data have;
 do year=1990 to 2000;
  output;
 end;
run;

data want;
 set have;
 date=mdy(1,1,year);
 format date yymmdd10.;
run;

K_S
Quartz | Level 8 K_S
Quartz | Level 8

I did and now the formatting is an issue. 

I got long numbers that I think are SAS date values. What format to use to have the dates appear as YYYY0101?

Reeza
Super User
If your variable is a date, you would change the format. If it's just a number, use MDY() to create a SAS date and then apply the correct format. The format you want is YYMMDDN8.

format dateVar yymmddn8.;

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=leforinforref&docsetTarge...
K_S
Quartz | Level 8 K_S
Quartz | Level 8

THANK YOU THANK YOU THANK YOU!!!!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1134 views
  • 2 likes
  • 3 in conversation