BookmarkSubscribeRSS Feed
lokeshbm
Calcite | Level 5

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;

 

             

 

 

 

8 REPLIES 8
LinusH
Tourmaline | Level 20

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
lokeshbm
Calcite | Level 5

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.

 

 

LinusH
Tourmaline | Level 20

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
lokeshbm
Calcite | Level 5

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

lokeshbm
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1172 views
  • 3 likes
  • 3 in conversation