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