![]() Let’s see if it can add well structure comments to the code: But let’s not stop here, all programmers know, well commented / annotated code is better than lonely code without comments. Let me see if ChatGPT can correct this:ĭone, we have an answer, it took a few steps, but like any junior programmer, we got to the solution in the end, but instead of “googling” the answer I “ChatGPT-ed” the answer. This single character is the first number from the date itself in the format yyy-mm-dd, thus implying the character date variable is being truncated. Look closely, you may notice that the newly created output dataset now contains a character date variable but with a length of 1, resulting in date values of just a single character. Now, you may think we have a solution, you would be wrong. ![]() ![]() ![]() I would like it to account for instances of when the numeric date variable could be missing to avoid those pesky log messages: Let me just tell ChatGPT the CATS function is not needed but let’s add a new condition I also want it to apply. So, I predicted this, with the correct format that CATS function is just not needed, the resulting numeric date of 22935, gets converted to after the PUT function, but then gets absolutely destroyed by the CATS function to. Good news the format is correct, bad news the CATS function ruins the result. Ok this time it began to use the DATE9 format which returns a result in the DDMMMYYYY format, which while it was generating the CATS function I began to think it was going to deconstruct DDMMMYYYY into YYYY, MMM and the DD components and rebuild them into the YYYY-MM-DD format, sadly however it did not, and the result was a character date variable with values like “17OC-T2-0”. However, even if ChaptGPT had used the correct format the newly added CATS function would result in the wrong answer anyway, because the yymmdd10 format adds the hyphens for you so this CATS step, which adds hyphen, is not required. But the format, yyyymmdd10, is still not correct, but we do get a slighlty different log message this time, a "note", not an "error". Remarkably it identified its own mistake and has tried to correct it, which is incredible. But like any new programmer, I will now shout at my computer, via ChatGPT, and say it did not work: The format we are looking for is the yymmdd10 format. The code is almost correct, apart from the format in the PUT statement, yyyy-mm-dd10, is not correct, and executing the code gives you an error. Now I like the fact ChatGPT included comments / annotation on the SAS® code, some programmers could learn a thing or two here. This is not the fault of ChatGPT, it is more a fault with my question, let’s try again: In clinical programming we see date variables as opposed to a singular (hardcoded) date. Not bad, it gave me some actual SAS code, albeit for a very specific example. So, let’s try a simple date conversion but this time I want actual SAS® code not just an explanation: Ok that is better, and it almost read my mind about converting a numeric date to character format or as ChatGPT put it “a human-readable format”. For those unaware, EXCEL and SAS® dates have a fundamental difference, long story short EXCEL dates start at January 1st, 1900, whereas SAS® dates start at January 1st, 1960. Well, it understands there is a difference, but I am not sure ChatGPT is 100% correct. But first I wanted to see if it understands the difference between a SAS® date and an EXCEL date: This was a good start, how about a problem every SAS® programmer tackles in their first year, date conversion. ChatGPT is covering my feed lately, and I am always a tad reluctant to try something which requires me to create account for yet another website, but from all the examples I am seeing I had to give it a go.įrom the plethora of examples I have seen, I was yet to see any SAS® examples so I thought I would have play, so I asked ChatGPT, a simple question:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |