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

Hi,

 

I'm working on a data which has numeric variable in the follwing way.

 

01.2015

04.2015

06.2015

09.2015

 

I tried converting it in to date format by using following code.

 

format variable yymmn6.;

 

I'm getting following output.

 

196001

196001

196001

196001

 

can any one please tell me the reason for the above output and how do I rectify the probem.

 

Thanks alot in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't know what a VDI is, but do bear in mind for future posts that this information helps us understand things at your end which we can't see.

 

No, SAS dates have to be complete dates with Day Month and Year as they are stored as a number of days from a set date.  The format applied to this number can show the data slightly differently, but cannot alter the underlying data.

Ie 

01JAN2015 = 20089 days <the number 20089 is what is stored in the variable.

 

If you just want to display first part after second, then a cat and scan can do it (though always recommended to store dates as numeric dates, it just makes life easier):

data want;
  my="01.2015";
  ym=cats(scan(my,2,"."),scan(my,1,"."));
run;

That is string manipulation.

 

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

To get a good answer it is recommended to post test data, in the form of a datastep (so we don't guess what you have), post output you want, and show code/logs of what does not work.

I am guesssing 01.2015 is a character variable and means Jan 2015?  If so then you need to input it as a date, give it a default say 01, and then format it to what you want (SAS dates are all numeric, number of days since a certain timepoint):

data want;
  my="01.2015";
  full_date=input(cats('01.',my),ddmmyy10.);
  format full_date yymmn6.;
run;
Haritha1
Fluorite | Level 6

Hi RW9,

 

I'm working in a VDI, so couldn't post the data and log information.

 

Thanks for your reply.

 

I did the same and it worked.

 

 

Is there a way to do it with out concatenating 01?

 

Thanks.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't know what a VDI is, but do bear in mind for future posts that this information helps us understand things at your end which we can't see.

 

No, SAS dates have to be complete dates with Day Month and Year as they are stored as a number of days from a set date.  The format applied to this number can show the data slightly differently, but cannot alter the underlying data.

Ie 

01JAN2015 = 20089 days <the number 20089 is what is stored in the variable.

 

If you just want to display first part after second, then a cat and scan can do it (though always recommended to store dates as numeric dates, it just makes life easier):

data want;
  my="01.2015";
  ym=cats(scan(my,2,"."),scan(my,1,"."));
run;

That is string manipulation.

 

 

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
  • 968 views
  • 0 likes
  • 2 in conversation