Hi,
I’m pretty new to SAS EG 8.3 and I’m trying to convert character date (ex. 20210111) to show as Year/Month (ex. 2021/01) but cant get it right.
Yes, this can be done in the query builder. You can create a computed column with the advanced expression editor, but you would use the INPUT function and the YYMMDD8. informat to convert the character string to a SAS date, and then apply the YYMMS7. format to display the SAS date correctly.
sorry for the multiple posts. tried to include a screen shot but it said it doesn't support file type and it wont let me delete the post.
You will need to create a new variable in a data step such as:
data want; set have; newdate = input(characterdate,yymmdd10.); format newdate yymms7. ; run;
Once you have a date value there are dozens of SAS supplied formats plus you can create your own format with Proc Format if you can't find one the matches your need.
Be aware the date value still has a day of the month component if you try to do any comparisons. The groups created by the format will work for most analysis, reporting and graphing procedures without modifying the individual values of the variable.
Can it be done in Computed Columns in Query Builder?
Yes, this can be done in the query builder. You can create a computed column with the advanced expression editor, but you would use the INPUT function and the YYMMDD8. informat to convert the character string to a SAS date, and then apply the YYMMS7. format to display the SAS date correctly.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.