BookmarkSubscribeRSS Feed
rajdeep
Pyrite | Level 9

No, I need it insdie a variable or a column, so that I can pull the relevant information from that inside SAS environment. Bcoz my input itself a SAS Code only. I am reading it like how we read the log files inside the SAS.

 

I'm just capturing the all the codes inside a variable which is been wriiten between proc and quit, it's appending line by line info and capturing fine for small codes, but for bigger proc sql queries it's cutting the string after 32767.

 

So, I just asked you earlier will your given code will capture the data between certain keywords like hello and there or proc or sql. or it will just append the data based on the length of the string value.(like len >50)

 

Anyways, I will test your code and will revert back. Apart from my requirement I just wanted to know for my knowledge that if there is a string more than 32767 characters then how to split the string and store it.

 

Thanks

Cheers......................

Oligolas
Barite | Level 11

Well I'm not sure if I would really proceed this with SAS.

One could try to extract all the procedures from the log using a powershell RegEx script, depending of the exact requirements it may reach a much better performance.

But using SAS, this should work for you:

%MACRO splitIntoVars(inputDS=,outputDs=,VarToSplit=,VarLimit=);
   %macro t;%mend t;
   /*
      Concatenates the *VarToSplit* variable into cat* variables of *VarLimit* length
      Whenever a cat variable has reached the *VarLimit* length, a new cat* variable is created
   */
   PROC SQL noprint;
      select ceil(sum(length(&VarToSplit.))/&VarLimit.) into:nvars TRIMMED
      from &inputDS.
      ;
   QUIT;

   DATA &outputDs.;
      %do n=1 %to &nvars.;
         length cat&n. $&VarLimit.;
         retain cat&n. '';
      %end;
      set &inputDS.;
      retain o_limit &VarLimit. o_reached 0 o__n 1;
      array vars(*) cat1-cat&nvars.;

      o_Remaining=length(&VarToSplit.);
      o_from=1;
      o_to=min(o_limit-o_reached,length(&VarToSplit.));
      do while(o_Remaining>=1);
         o_text=substr(&VarToSplit.,o_from,o_to);
         %*Debug: put o__n= name= o_reached= o_remaining= o_from= o_to= o_text=;
         vars(o__n)=cats(' ',vars(o__n),substr(&VarToSplit.,o_from,o_to));   
         o_Remaining=o_Remaining-o_to;
         o_reached=o_reached+o_to;
         o_from=o_from+o_to;
         o_to=min(o_Remaining,o_limit);
         if o_reached eq o_limit then do;
            o__n=o__n+1;         
            o_reached=0;
         end;
      end;
      drop o_:;
   RUN;
%MEND splitIntoVars;
%splitIntoVars(inputDS=sashelp.class,outputDs=test,VarToSplit=name,VarLimit=50);
________________________

- Cheers -

rajdeep
Pyrite | Level 9

Thanks Oligoals for your effort. Let me tell you what I had done for this.

 


data D1;
set test2; 
/* cnt=length(sas); */
cnt1=length(sas_code);
   if 
   Findw(sas_code,'Proc') or Findw(sas_code,'PROC') or Findw(sas_code,'proc') or 
   scan(sas_code,1)='Data' or Scan(sas_code,1)='data' or scan(sas_code,1)='DATA' then 
   do;
   l+1;
   end;
   else do;
   l+0;
   end;

run;



data D2;
/* length cat $32690; */
length cat $32690;
do until (last.l);
set D1;
by l notsorted;
cat=catx(' ',cat,strip(sas_code)); 
end;
run;

 

So, in the D2 dataset it's appending the query, so when the query length is going beyond 32767 then it's trimming it. I would like to store the remaining in other variable in the D2 datastep itself.

 

 NOTE: test2 is the sas code itself.

Is it possible in realtime?

Oligolas
Barite | Level 11

Did you try the code I sent you?

________________________

- Cheers -

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 18 replies
  • 3830 views
  • 0 likes
  • 6 in conversation