Hi all, I need to update the save date in a bunch of program headers. For confidentiality reasons, most of the program header was omitted but it looks like this:
****************************************************
SAVE DATE OF PROGRAM
(PRIOR TO FIRST DELIVERY): 21OCT2022
*******************************************************;
Pretend I have 60 programs in the same folder where I need to change the date to the current date, in this case: 07NOV2022. How would I accomplish this? No way am I trying to open each program one at a time to change the date. It's inside a comment block at the top of the program, else I'd use an automatic SAS macro variable like SYSDATE9. I will need to keep the program the header the same since it's standardized. Looking for help to automate it
Pretend I have 60 programs in the same folder where I need to change the date to the current date, in this case: 07NOV2022. How would I accomplish this? No way am I trying to open each program one at a time to change the date.
You could use a program like Notepad++ that can find all programs in a folder and change whatever text is there to whatever else you specify, such as &sysdate.
But other than that, I am having difficulty understanding what the problem requirements are. Forgetting the issue that you have 60 programs in the same folder, what is the desired result for program 1? Does this date in the header change every day?
The date has to be changed to the current date if it's not already.
@tarheel13 wrote:
The date has to be changed to the current date if it's not already.
It has to be changed every day in all 60 of the programs? So tomorrow they all have text 08NOV2022? And the next day they all have text 09NOV2022? And so on?
It's throwing warnings in the log. I don't think it has to be changed daily.
@tarheel13 wrote:
It's throwing warnings in the log. I don't think it has to be changed daily.
This is the first that you have mentioned this. Please show us the warnings and associated code as it appears in the log. (And every time in the future, if there are warnings or errors in the log, show us the log including the code as it appears in the log). Please copy the log as text and paste it into the window that appears when you click on the </> icon.
But honestly, I'm still lost on what the requirements are. Maybe someone else understands.
I wanted to automate it rather than change the date manually. the warnings are probably intentionally put there and not usual SAS warnings.
@tarheel13 wrote:
I wanted to automate it rather than change the date manually. the warnings are probably intentionally put there and not usual SAS warnings.
Automate what? I still don't grasp that part of the project.
Today, you want to put the date 07NOV2022 into the file headers for all 60 programs? Then tomorrow, what? And the day after that, what?
@tarheel13 wrote:
The date has to be changed to the current date if it's not already.
Why?
Did you make other changes to these files today and forget to update the comment block?
Are you changing the "date" in a comment?
A data step to 1) read the file as text , 2) write ,most, of the file as existing text and 3) modify the date on one line? Is the line that the date appears on the same in all of the files? Is the column the same?
hey I can show the blank program header later and yes, it is in a comment block. anyway, the reason this all matters is because there are audits. So there is a modification history section and a last save date prior to delivery. Yesterday, someone was expecting me to update like 60 programs manually and I want to automate this so I never have to open 60 programs again and change the program header. Yesterday, I stumbled across a macro that may have some code I can use. So the save date prior to FIRST delivery does not seem as if it should be changed since the first delivery already happened on this project. However, then the modification history needs to match LAST SYSTEM SAVE DATE. someone has a macro checking the program header and it will put warnings if last modification date and last system save date are not equal. things like that I'm trying to fix and not do manually. so if someone went and made modifications today, then the modification history would have to say 08NOV2022 and the date the program was saved should also be 08NOV2022. trying to find a way to fix the dates without opening them one at a time. additionally, yesterday I had to update the protocol number in program header like 60 times just to use _ instead of -.
Agree that using a data step will work. I am thinking to get the program names in a macro variable list and loop over it and then write 2 data steps that can change the necessary things like protocol number or save/modification dates. ultimately, the time spent coming up with a solution for this will be worth it as I won't have to update 60+ programs one at a time again by opening up the program in SAS EG and revising the header block.
Big picture, wouldn't it be better to use a version control tool (e.g. git) for this need? That would give you all the audit trail of history of changes, etc, without trying to manually track file modification dates on comments.
UNIX systems provide the perfect tool for conditional, scripted editing of text files, it's called awk.
yea I was disappointed that we aren't using UNIX here. I know unix commands
I can hardly grasp why it could be necessary to change the header of a program without modifying its contents. But if i had to do it, i would use a scripting language, like awk on linux or powershell on windows.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.