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.
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.
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;
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.