Hi All,
@Reeza @KurtBremser @ChrisHemedinger @Patrick @LinusH @Tom
I am trying to read few sas programs and create a dataset from it and extract some metadata from it.
So basically i am trying to read the whole program step by step and add some flags like below.
We are trying to flag the step_no: which is the count for the complete step, whether its a proc or a proc sql or datastep.
data_Step_no- for each value present for the step_no, assign incremental count till the datastep end.
proc_Step_no- for each value present for the step_no, assign incremental count till the proc end(or basically a run;).
We are trying to do this using @@ and mutiple find statements, however couldn't make it working for the data_step_no and proc_step_no. Do you think there is any such way to accomplish this task. We are trying to automate our migration. we are using sas EG7.1 on unix and sas 9.2
code | rec_no | step_no | data_step_no | proc_step_no |
data want; | 1 | 1 | 1 | . |
infile tmp truncover end=done; | 2 | 1 | 2 | . |
input @1 father $9. mother $10. address $40.; | 3 | 1 | 3 | . |
input child $9. age ?? 3.0 @@; | 4 | 1 | 4 | . |
run; | 5 | 1 | 5 | . |
DATA COMMAS; | 6 | 2 | 1 | . |
INFILE DATALINES DLM=','; | 7 | 2 | 2 | . |
INPUT ID HEIGHT WEIGHT GENDER $ AGE; | 8 | 2 | 3 | . |
DATALINES; | 9 | 2 | 4 | . |
1,68,144,M,23 | 10 | 2 | 5 | . |
2,78,202,M,34 | 11 | 2 | 6 | . |
3,62,99,F,37 | 12 | 2 | 7 | . |
4,61,101,F,45 | 13 | 2 | 8 | . |
; | 14 | 2 | 9 | . |
run; | 15 | 2 | 10 | . |
PROC PRINT; | 16 | 3 | . | 1 |
TITLE 'Example 2.1'; | 17 | 3 | . | 1 |
RUN; | 18 | 3 | . | 1 |
DATA AMPERS; | 18 | 4 | 1 | . |
INPUT NAME & $25. AGE GENDER : $1.; | 18 | 4 | 2 | . |
DATALINES; | 18 | 4 | 3 | . |
RASPUTIN 45 M | 18 | 4 | 4 | . |
BETSY ROSS 62 F | 18 | 4 | 5 | . |
ROBERT LOUIS STEVENSON 75 M | 18 | 4 | 6 | . |
; | 18 | 4 | 7 | . |
run; | 18 | 4 | 1 | . |
PROC PRINT; | 18 | 5 | . | 2 |
TITLE 'Example 4'; | 18 | 5 | . | 2 |
RUN; | 18 | 5 | . | 2 |
/* this is comment*/ | 19 | . | . | . |
How does analysing the structure of your SAS programs programmatically help to automate migration? I'm assuming you are migrating from SAS 9.2 to 9.4.
In my experience, the best way to migrate is to set up your target SAS servers as similar as possible to your source SAS servers then test all of your key programs in the new environment one by one manually. Running your jobs in batch mode is the most productive way. The way you are trying to approach it simply won't work because it is near impossible to analyse SAS programs with high accuracy.
@mnjtrana - Editors like Notepad++ can be very helpful here. They can search all SAS programs in a particular folder for example and list all occurrences of a search string like a dataset name that needs to change.
I second what @SASKiwi writes. May be tell us what you're trying to get out of such analysis. There might be other ways to get there.
It wouldn't be hard to write some code for the simple sample program you've posted but what when it comes to dynamic and data driven code (macros, call execute() etc.).
When I want to know in which program a specific dataset or infile is used, I find all the logs from the previous month (because that covers ALL program runs) and grep for the dataset/filename:
find /sas/log -type f -name \*.log.202003\* -exec grep "MYLIB.MYDATA" {} \; -print
That's much easier than doing it with SAS.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.