01-20-2016 02:18 AM
I need to import a sas program i.e .SAS file,The output dataset should have text between the ; [semicolan] as observations,
Any help on this is much appriciated.
ex: data hello; set hello1;
/* calculated field*/
Output : data hello;
/* calculated field*/ run;
01-20-2016 02:43 AM
Perhaps you could explain why you wish to do this?
But it seems you could just use the whole input record using the automatic _infile_variable, assign to a char variable.
In your example, it seems you wish to split records. That can be done, but there are some traps. Like if you have a ; within a character constant (and does not point out end of SAS program line).
01-20-2016 02:56 AM
Hi, My objective is to seperate/output the calculated variables from the code.So if i am able to split the code in to records between ; semicolan,I can further apply some conditions and output only those. In this case I want to output only x=a+b.
01-20-2016 05:00 AM
As i said, it can be quite cumbersome to split records, since ; can occur not only for end of statement. macro for instance.
And then you have SQL, which would probably look awful with this logic.
If you want to document all calculations, you might be a candidate for using a metadata ETL tool, like DI Studio.
You can use scan() and substr() functions with explicit output statement to split records.
01-26-2016 02:18 AM
Thanks for your prompt reply.I know this is bit complicated and awful,but If I can output/cover 60 to 70% of the calculated variables that are created in the code that should do and I need this for documentation purpose.
I have imported the code and split the text between ; [semicolan] in to observations. I am now trying to create a loop which checks and cleans the data leaving the calculated fields.
I am not sure this is the best approach,Any suggesitions or help or code [with some sample examples] on this highly appiciated as I have to submit the code asap.
01-26-2016 04:27 AM
Your statements are at odds though. What is the purpose of this "documentation"? Is it for some sort of QC, if so then it fails straight away as documenting what it does is not QC. What do you mean by "submit the code"?
To be honest if you have to do this, then I would suggest going through each program and working out what it is doing. As I mentioned before, it is very complicated, what consititutes a calculated variable? Do loops can create variables, functions, arrays, retain, length, attrib statements etc. Strings could be more complicated, especically if they have used excplicit conversion techniques (input). How will you get calculated variables from procedures, say means for example.
01-27-2016 03:36 AM
What you said is right its getting complicated and complicated.What i meant by "submit the code" is to share the code to the testing team.
As you suggested going through each program and working out what it is doing :
Can you give an example for a basic data step for the above please?.
01-27-2016 04:03 AM
Its not a programmed approach I am suggesting. It requires a programmer to manually go through the code and understand it. It simply comes from the failure to document things prior to programming.
Remember for the future:
Document, document, document, program, test, document, cycle.
Documentation is far more important than programming.
01-20-2016 05:18 AM
I totally agree with @LinusH. What you are attempting to do is in part like the SAS compiler. You will need to do a lot of work to make this run, and at the end of the day is it worth it. Following on from SDLC, you will have defined a Functional Design Specification, which details what the program does, outputs etc. This document is the specification, you program from that and test against it. Why do this, well, the reason is because you are now trying to fit the specification and testing around code you have written. It is all kinds of problems, and wouldn't be considered validated.
Specification, document, review, program, test, release, lifecycle.