DATA Step, Macro, Functions and more

How to import SAS Programme

Reply
Occasional Contributor
Posts: 7

How to import SAS Programme

Hi,

 

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;

      x=a+b;

     /* calculated field*/

     run;

 

Output :  data hello;

               set hello1

               x= a+b;

               /* calculated field*/  run;

 

             

 

 

 

Super User
Posts: 5,437

Re: How to import SAS Programme

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).

Data never sleeps
Occasional Contributor
Posts: 7

Re: How to import SAS Programme

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.

 

 

Super User
Posts: 5,437

Re: How to import SAS Programme

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.

Data never sleeps
Occasional Contributor
Posts: 7

Re: How to import SAS Programme

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.

Super User
Super User
Posts: 7,988

Re: How to import SAS Programme

Hi,

 

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.

Occasional Contributor
Posts: 7

Re: How to import SAS Programme

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?.

 

Thanks,

Lokesh

Super User
Super User
Posts: 7,988

Re: How to import SAS Programme

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.

Super User
Super User
Posts: 7,988

Re: How to import SAS Programme

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.

 

Simply put:

Specification, document, review, program, test, release, lifecycle.

Ask a Question
Discussion stats
  • 8 replies
  • 299 views
  • 3 likes
  • 3 in conversation