BookmarkSubscribeRSS Feed
WorkingMan
Calcite | Level 5

Hi, i have a column with the value of "201808" in numeric.

I wish to convert this column in yymmn6. but i failed.

 

 

Sample code:

data have ;
  numPeriod =201808;
  format numPeriod yymm6.
  /*The code above will give me wrong value of 251707(or similar)*/

run ;

 

Which part did i do wrongly?

3 REPLIES 3
Reeza
Super User

@WorkingMan wrote:

Hi, i have a column with the value of "201808" in numeric.

I wish to convert this column in yymmn6. but i failed.

 

 

Sample code:

data have ;
  numPeriod =201808;
  format numPeriod yymm6.
  /*The code above will give me wrong value of 251707(or similar)*/

run ;

 

Which part did i do wrongly?



A date always has a day component not just the year and month. 

 

If you’re manually creating the date use MDY() function instead. 

 

If you’re trying to convert a number to a date, either do the math manually to get month/year. Or convert it to a character and then back to a number as a SAS date. 

 

Date = input(put(oldDate, 8. -l), yymmn6.);
Format date yymmn6.;

If the yymmn6 throws an error you’ll need to find the right informat. I would probably add a 01 for the day at the end and use yymmdd10 if that happened. 

 

 

Tom
Super User Tom
Super User

Dates are the number of days since 1960.  201,808 days after 1960  is pretty far in the future.

You also need to pick an actual date, you cannot store a single number that represents 28,29,30 or 31 individual dates.  Generally the first of the month is used.

  numPeriod =201808;
  PeriodStart = mdy(mod(numPeriod,100),1,int(numPeriod/100));
  format numPeriod comma7. PeriodStart yymm6. ;
PeterClemmensen
Tourmaline | Level 20
data _null_;
   numPeriod =201808;
   date=input(put(numPeriod, 8. -l), yymmn6.);
   
   put date date9.;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 7817 views
  • 1 like
  • 4 in conversation