Masking sas code

Reply
Super Contributor
Posts: 371

Masking sas code

Please, I have a table with sas code and i want to extract some lines from my table :  select text from table where TEXT='xxx';  Thank you

table:

TEXT

if xxx then yyyyy do;

xxxxx

end

proc sql;

create table

From

quit;

%let v=

%macro ggg;

%mend ggg;

Esteemed Advisor
Posts: 6,698

Re: Masking sas code

Your question makes no sense to me. Could you please rephrase it in a more understandable way?

Because at the moment I think all you need is a where condition, which is not difficult at all.

Why do you store SAS code in a table?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 371

Re: Masking sas code

I have a sas program and I want to extract the variables rule from my pogram

like this as an exemple.

length V 5.;

format  V best32.;

W=2*T;

T=P*L;

V=W*T;

Grand Advisor
Posts: 10,235

Re: Masking sas code

Provide some more detailed input and what the output should look like.

Super Contributor
Posts: 371

Re: Masking sas code

Thank you for your message.

I have a sas program( it is my input) and I want to extract the vaiable rules.

SAS Super FREQ
Posts: 8,721

Re: Masking sas code

Hi:

What is a variable "rule"? Can you show an ACTUAL example of the data/program you have and an ACTUAL example of the output you expect or of the type of output you want? If you can't post an example of real data or a real program, then you need to show a program and then give a concrete example of the type of output you want. Saying that you "want to extract the variable rules" doesn't tell anyone whether you want an output dataset, whether you want a report, what is a variable rule, how do you tell a variable rule from any other statement or data. Which of your statements would be considered variable "rules" and why? You said that you had a program, but usually, a program is a complete program. You only showed a partial program. Essentially, you will have to read in the program using an INFILE and INPUT statements.

  It will be of more help to everyone if you can draft a complete sample question with an example of what you are starting with AND a description of the selection/extraction rules for creating your output AND a description of what type of output you need (dataset or report) .
 

For example, here's a sample question:

I have a table with some information

My Table

---------------

order   line

1         x=y;

2         12345

3         *this is a comment;

4         p=24;

5         run;

6         *this is the end, this is the end, my friend;

and I want to extract any line that starts with an asterisk '*'. I need to create a new dataset that contains only these observations. In this data above, my output dataset would look like this:

order     line

3            *this is a comment;

6            *this is the end, this is the end, my friend;

  In which case, it would be easy for someone to suggest an example program based on using the INDEX, FIND and/or SUBSTR functions, coupled with the OUTPUT statement. Probably, the program would need an INFILE statement to point to the location of the file and then a INPUT statement to "parse" the lines.

data mytable;

  length line $100;

  infile datalines dlm='~' dsd;

  input order line $;

return;

datalines4;

1~x=y;

2~12345

3~*this is a comment;

4~p=24;

5~run;

6~*this is the end, this is the end, my friend;

;;;;

run;

    

title; footnote;

ods html file='c:\temp\before_after.html';

proc print data=mytable noobs;

  title '1) Original File';

  var order line;

run;

    

data newtable;

  set mytable;

  ** this IF statement could be added to the original program that reads;

  ** in the data. It depends on whether you need to keep a copy of the original;

  if substr(line,1,1) = '*' then output;

run;

   

proc print data=newtable noobs;

  title '2) Extracted Lines';

  var order line;

run;

ods html close;

cynthia

Super Contributor
Posts: 371

Re: Masking sas code

Thank you for your message.

Sorry, if I was not clear in my question. I will try this one

> I can have a sas program with more than 9000 lines of code or more (some times) !!

To resume :

> My input is a sas program with more than 9000 lines of code( you can have the sas proc: sql, iml, print, data set, sas maco, all things, you can get in sas base)

> I want to extract the the rules of the variables in my output( I call it : table target), my variables in the output, they passed by an other tables ( I call these tables : table source)

> I want to have a report likes this :

VARIABLERULETABLE TARGETTABLE SOURCE
VLength V 6 ;
Format V best32.;
V=2w+r-2g;
......
TABTAG1TABSR1

Note : Yes , I agree with that, we can get the variable in the code, but this does not mean, we have made a modification on the variable( as you show with proc print with your exemple), but i am really interested by the real modification, that can modify the result at the end

Grand Advisor
Posts: 17,420

Re: Masking sas code

I'm very curious as to why you're doing this.

I would treat this as a text mining operation to some point, reading in all the code and then separating each section into and individual proc/data step. You can parse each line into individual component using the semicolon as a delimiter and go from there. I'm not sure if searching for the = will capture all variable transformations but I'm not 100% sure what you're after either.

Super Contributor
Posts: 371

Re: Masking sas code

Thank you for your interest.

It is intersting for some  reasons( technical, domaine, fonctional,..)

Yes, "=" can help, we can not get all rules:

If I have some thing likes this

proc sql;

create table out1 as

select  trt1 as v

even with "=", we will have some informations, but , we will not extract in which data, we have make this modification

like this

data out2;

  set out1;

  v=2w-r;

run;

SAS Super FREQ
Posts: 8,721

Re: Masking sas code

Hi,

  It seems to me that you are essentially wanting to duplicate what SAS does at word scanning phase and compile phase, before execution phase. That is a big task. I agree with Reeza -- this is more of a text mining exercise. I would think it would help if you can refine your requirements a bit more. For example it is not clear to me why your LENGTH "rule" is one row on the report, but your FORMAT "rule" has FORMAT V on one line and then has the best32. on the next line. This is inconsistent with the way you represent the "rule" for LENGTH.

cynthia

Super Contributor
Posts: 371

Re: Masking sas code

Hi Cynthia

Yes, you're right,

Sorry, I made a mistake, I want like this 

Length V 6 ;

Format V best32.;

As I said before, this exercise has a some reasons( technical, functional, domain)

It is also very intersting to see in the report some thing inconsistent in sas synthax, in domain, in functional  

Grand Advisor
Posts: 17,420

Re: Masking sas code

What's domain/functional and an example of inconsistency.

Super Contributor
Posts: 371

Re: Masking sas code

It 's can be any domain,

Let us take an exemple, if you choose the  domain XXXX

You define a variable tax : likes this Tax=a*var1+b*var2+var3*omega1

but in other tables: you have :

a*var1+b*var2+zeta3*omega1+epsilon

or a*var1+b*var2+var3*omega1+teta

It is just an exemple.

If we can list the rules of the variable one after one, it is some thing very ineresting because, we will have a good vision for the processus of the creation(or transformation) of the variable in a big program

Super Contributor
Posts: 371

Re: Masking sas code

What's about sas integration. we can not use it ?

Ask a Question
Discussion stats
  • 13 replies
  • 400 views
  • 0 likes
  • 5 in conversation