BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

 

A data _null_ step shows that my approach works without the quoting issue:

 

data _null_;
_statistic_="Average-Quantile";
_arg1_=.;
want=compress(cats(_statistic_, _arg1_),".-");
put want=;
run;

But when I use the compress function within the call execute construct, I cannot make it work. 

I don't know how to pass the arguments "-." to the compress function. I seems like I have to quote the quote. 

"'"

"""""

'||"'"

???

I'm aware that my code below cannot be reproduced without data and macro variables, ...

But it works when I replace the error producing line (compress) with a hard-coded value. 

 

data _null_;
set xdata2;
call execute('
%let varlist="";
proc cas;
    action columninfo result=r /table={name="'|| strip(name) || '", caslib="ORACASLIB"};   
    empty = 0;
    if (r.columnInfo.nrows <= 0) then do;
      empty = 1;
      rc = symput("emptyTable", (string)empty);
    end;
    else do;
      columns = "";
        do i = 1 to r.columninfo.nrows;
      if ^index(UPCASE(r["columninfo"][i,4]), "CHAR") or 1=2 THEN do;
            symput("col", quote(r[1,i].column));
            columns = columns||", "||symget("col");
      end;
      end;
      symput("varlist", substrn(columns,2,length(columns)-1));
    end;
run;

quit;

proc cas;
dataPreprocess.rustats / 
table={name="'|| strip(name) || '", caslib="ORACASLIB"}, inputs={' || symget(varlist) || '},
requestpackages={{allLocations=TRUE, allSkewnesses=TRUE}},
casoutstats={name="mydata_rustats",caslib="casuser", replace=true};
run;

transpose.transpose /
table={caslib="casuser", name="mydata_rustats", groupby={"_variable_"}, 
computedvars={{name="newid",format="$20."}},

computedvarsprogram="newid=' || compress(cats(_statistic_, _arg1_),".-") ||';"},
transpose={"_value_"}, id={"newid"}, casOut={caslib="casuser", name="'|| catx("_", strip(name)) || '", 
replace=true};
run;
quit;');
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

CALL EXECUTE executes some macro code immediately. This may be the problem. There is also an error in your code, which is this:

symput("varlist", substrn(columns,2,length(columns)-1));

It is CALL SYMPUT, not just SYMPUT.

 

There may also be some problems with nested quotes in your code, I am not sure. I generally do not use CALL EXECUTE for such solutions, I think it works better to generate a SAS program and %INCLUDE that. That way, you can first look at the code, to see if it looks all right, then try and submit it. If it works OK, you can put the %INCLUDE (may want to use the /SOURCE2 option) in your original code.

 

Something like this:

filename tempsas temp; /* temporary file, gets deleted when freed or reallocated */
data _null_;
set xdata2;
file tempsas;
put 
'%let varlist="";'/
'proc cas;'/
'    action columninfo result=r /table={' name= ', caslib="ORACASLIB"};'/   
'    empty = 0;' /
/* etcetera */
'quit;';
run;

You will then have a file containing all the code generated. Open it, and see if it looks OK. If it does, try submitting the code down to the first "quit;" statement, and see if it generates the result you want. Then try submitting the rest of the file, and see if that also works.

View solution in original post

3 REPLIES 3
s_lassen
Meteorite | Level 14

CALL EXECUTE executes some macro code immediately. This may be the problem. There is also an error in your code, which is this:

symput("varlist", substrn(columns,2,length(columns)-1));

It is CALL SYMPUT, not just SYMPUT.

 

There may also be some problems with nested quotes in your code, I am not sure. I generally do not use CALL EXECUTE for such solutions, I think it works better to generate a SAS program and %INCLUDE that. That way, you can first look at the code, to see if it looks all right, then try and submit it. If it works OK, you can put the %INCLUDE (may want to use the /SOURCE2 option) in your original code.

 

Something like this:

filename tempsas temp; /* temporary file, gets deleted when freed or reallocated */
data _null_;
set xdata2;
file tempsas;
put 
'%let varlist="";'/
'proc cas;'/
'    action columninfo result=r /table={' name= ', caslib="ORACASLIB"};'/   
'    empty = 0;' /
/* etcetera */
'quit;';
run;

You will then have a file containing all the code generated. Open it, and see if it looks OK. If it does, try submitting the code down to the first "quit;" statement, and see if it generates the result you want. Then try submitting the rest of the file, and see if that also works.

acordes
Rhodochrosite | Level 12

I can use it. But I don't know how to inspect / see the temp file...

 

%include tempsas / source2;
yabwon
Onyx | Level 15

if you have temporary file use:

filename tempsas list;

to see its location in the log;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 515 views
  • 1 like
  • 3 in conversation